Skip to content

Commit 910e6b5

Browse files
committed
os: document CopyFS behavior for symlinks in destination
Also clarify the permissions of created files, and note that CopyFS will not overwrite files. Update a few places in documentation to use 0oXXX for octal consts. For #62484 Change-Id: I208ed2bde250304bc7fac2b93963ba57037e791e Reviewed-on: https://go-review.googlesource.com/c/go/+/600775 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 074f276 commit 910e6b5

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/os/dir.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,17 @@ func ReadDir(name string) ([]DirEntry, error) {
132132
// CopyFS copies the file system fsys into the directory dir,
133133
// creating dir if necessary.
134134
//
135-
// Newly created directories and files have their default modes
136-
// where any bits from the file in fsys that are not part of the
137-
// standard read, write, and execute permissions will be zeroed
138-
// out, and standard read and write permissions are set for owner,
139-
// group, and others while retaining any existing execute bits from
140-
// the file in fsys.
135+
// Files are created with mode 0o666 plus any execute permissions
136+
// from the source, and directories are created with mode 0o777
137+
// (before umask).
141138
//
142-
// Symbolic links in fsys are not supported, a *PathError with Err set
143-
// to ErrInvalid is returned on symlink.
139+
// CopyFS will not overwrite existing files, and returns an error
140+
// if a file name in fsys already exists in the destination.
141+
//
142+
// Symbolic links in fsys are not supported. A *PathError with Err set
143+
// to ErrInvalid is returned when copying from a symbolic link.
144+
//
145+
// Symbolic links in dir are followed.
144146
//
145147
// Copying stops at and returns the first error encountered.
146148
func CopyFS(dir string, fsys fs.FS) error {

src/os/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func ExampleFileMode() {
6161
log.Fatal(err)
6262
}
6363

64-
fmt.Printf("permissions: %#o\n", fi.Mode().Perm()) // 0400, 0777, etc.
64+
fmt.Printf("permissions: %#o\n", fi.Mode().Perm()) // 0o400, 0o777, etc.
6565
switch mode := fi.Mode(); {
6666
case mode.IsRegular():
6767
fmt.Println("regular file")

src/os/file.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func Open(name string) (*File, error) {
366366
}
367367

368368
// Create creates or truncates the named file. If the file already exists,
369-
// it is truncated. If the file does not exist, it is created with mode 0666
369+
// it is truncated. If the file does not exist, it is created with mode 0o666
370370
// (before umask). If successful, methods on the returned File can
371371
// be used for I/O; the associated file descriptor has mode O_RDWR.
372372
// If there is an error, it will be of type *PathError.
@@ -606,11 +606,11 @@ func UserHomeDir() (string, error) {
606606
// On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and
607607
// ModeSticky are used.
608608
//
609-
// On Windows, only the 0200 bit (owner writable) of mode is used; it
609+
// On Windows, only the 0o200 bit (owner writable) of mode is used; it
610610
// controls whether the file's read-only attribute is set or cleared.
611611
// The other bits are currently unused. For compatibility with Go 1.12
612-
// and earlier, use a non-zero mode. Use mode 0400 for a read-only
613-
// file and 0600 for a readable+writable file.
612+
// and earlier, use a non-zero mode. Use mode 0o400 for a read-only
613+
// file and 0o600 for a readable+writable file.
614614
//
615615
// On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive,
616616
// and ModeTemporary are used.

0 commit comments

Comments
 (0)