File: writeops.go

package info (click to toggle)
golang-github-bep-overlayfs 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 164 kB
  • sloc: makefile: 2
file content (96 lines) | stat: -rw-r--r-- 2,584 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package overlayfs

import (
	"os"
	"time"

	"github.com/spf13/afero"
)

// Chmod changes the mode of the named file to mode.
func (ofs *OverlayFs) Chmod(name string, mode os.FileMode) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().Chmod(name, mode)
}

// Chown changes the uid and gid of the named file.
func (ofs *OverlayFs) Chown(name string, uid, gid int) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().Chown(name, uid, gid)
}

// Chtimes changes the access and modification times of the named file
func (ofs *OverlayFs) Chtimes(name string, atime, mtime time.Time) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().Chtimes(name, atime, mtime)
}

// Mkdir creates a directory in the filesystem, return an error if any
// happens.
func (ofs *OverlayFs) Mkdir(name string, perm os.FileMode) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().Mkdir(name, perm)
}

// MkdirAll creates a directory path and all parents that does not exist
// yet.
func (ofs *OverlayFs) MkdirAll(path string, perm os.FileMode) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().MkdirAll(path, perm)
}

// OpenFile opens a file using the given flags and the given mode.
func (ofs *OverlayFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
	if flag&(os.O_WRONLY|os.O_RDWR|os.O_APPEND|os.O_CREATE|os.O_TRUNC) != 0 {
		if !ofs.firstWritable {
			return nil, os.ErrPermission
		}
		return ofs.writeFs().OpenFile(name, flag, perm)
	}
	return ofs.Open(name)
}

// Remove removes a file identified by name, returning an error, if any
// happens.
func (ofs *OverlayFs) Remove(name string) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().Remove(name)
}

// RemoveAll removes a directory path and any children it contains. It
// does not fail if the path does not exist (return nil).
func (ofs *OverlayFs) RemoveAll(path string) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().RemoveAll(path)
}

// Rename renames a file.
func (ofs *OverlayFs) Rename(oldname, newname string) error {
	if !ofs.firstWritable {
		return os.ErrPermission
	}
	return ofs.writeFs().Rename(oldname, newname)
}

// Create creates a file in the filesystem, returning the file and an
// error, if any happens.
func (ofs *OverlayFs) Create(name string) (afero.File, error) {
	if !ofs.firstWritable {
		return nil, os.ErrPermission
	}
	return ofs.writeFs().Create(name)
}