Debian Codegraph @

storage/file.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // blame: jnml, labs.nic.cz
6
7 package storage // import "modernc.org/fileutil/storage"
8
9 import (
10 "os"
11 )
12
13 // FileAccessor is the concrete type returned by NewFile and OpenFile.
14 type FileAccessor struct {
15 *os.File
16 }
17
18 // Implementation of Accessor.
19 func (f *FileAccessor) BeginUpdate() error { return nil }
20
21 // Implementation of Accessor.
22 func (f *FileAccessor) EndUpdate() error { return nil }
23
24 // NewFile returns an Accessor backed by an os.File named name, It opens the
25 // named file with specified flag (os.O_RDWR etc.) and perm, (0666 etc.) if
26 // applicable. If successful, methods on the returned Accessor can be used for
27 // I/O. It returns the Accessor and an Error, if any.
28 //
29 // NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op.
30 func NewFile(name string, flag int, perm os.FileMode) (store Accessor, err error) {
31 var f FileAccessor
32 if f.File, err = os.OpenFile(name, flag, perm); err == nil {
33 store = &f
34 }
35 return
36 }
37
38 // OpenFile returns an Accessor backed by an existing os.File named name, It
39 // opens the named file with specified flag (os.O_RDWR etc.) and perm, (0666
40 // etc.) if applicable. If successful, methods on the returned Accessor can be
41 // used for I/O. It returns the Accessor and an Error, if any.
42 //
43 // NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op.
44 func OpenFile(name string, flag int, perm os.FileMode) (store Accessor, err error) {
45 var f FileAccessor
46 if f.File, err = os.OpenFile(name, flag, perm); err == nil {
47 store = &f
48 }
49 return
50 }