Przeglądaj źródła

Preserve the permission of a newly created directory

We need an explicit chmod() when creating a new directory.
Otherwise a new directory may be created with a different permission
from the one received from an originating device, because the umask
is applied to the mode given to mkdir().
The incorrect permission is later sent back to the originating device
and the original permission will be lost.
KAMADA Ken'ichi 11 lat temu
rodzic
commit
ac7097b4d0
1 zmienionych plików z 5 dodań i 1 usunięć
  1. 5 1
      internal/model/rwfolder.go

+ 5 - 1
internal/model/rwfolder.go

@@ -489,7 +489,11 @@ func (p *rwFolder) handleDir(file protocol.FileInfo) {
 		// we can pass it to InWritableDir. We use a regular Mkdir and
 		// we can pass it to InWritableDir. We use a regular Mkdir and
 		// not MkdirAll because the parent should already exist.
 		// not MkdirAll because the parent should already exist.
 		mkdir := func(path string) error {
 		mkdir := func(path string) error {
-			return os.Mkdir(path, mode)
+			err = os.Mkdir(path, mode)
+			if err != nil || p.ignorePerms {
+				return err
+			}
+			return os.Chmod(path, mode)
 		}
 		}
 
 
 		if err = osutil.InWritableDir(mkdir, realName); err == nil {
 		if err = osutil.InWritableDir(mkdir, realName); err == nil {