Browse Source

Merge pull request #1401 from Zillode/fix-chmod-android

Fix chmod android
Jakob Borg 10 years ago
parent
commit
815e538f10
3 changed files with 18 additions and 16 deletions
  1. 8 7
      internal/model/puller.go
  2. 8 7
      internal/model/sharedpullerstate.go
  3. 2 2
      test/util.go

+ 8 - 7
internal/model/puller.go

@@ -718,13 +718,14 @@ func (p *Puller) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocksSt
 	}
 
 	s := sharedPullerState{
-		file:       file,
-		folder:     p.folder,
-		tempName:   tempName,
-		realName:   realName,
-		copyTotal:  len(blocks),
-		copyNeeded: len(blocks),
-		reused:     reused,
+		file:        file,
+		folder:      p.folder,
+		tempName:    tempName,
+		realName:    realName,
+		copyTotal:   len(blocks),
+		copyNeeded:  len(blocks),
+		reused:      reused,
+		ignorePerms: p.ignorePerms,
 	}
 
 	if debug {

+ 8 - 7
internal/model/sharedpullerstate.go

@@ -29,11 +29,12 @@ import (
 // updated along the way.
 type sharedPullerState struct {
 	// Immutable, does not require locking
-	file     protocol.FileInfo
-	folder   string
-	tempName string
-	realName string
-	reused   int // Number of blocks reused from temporary file
+	file        protocol.FileInfo
+	folder      string
+	tempName    string
+	realName    string
+	reused      int // Number of blocks reused from temporary file
+	ignorePerms bool
 
 	// Mutable, must be locked for access
 	err        error      // The first error we hit
@@ -96,7 +97,7 @@ func (s *sharedPullerState) tempFile() (io.WriterAt, error) {
 		return nil, err
 	} else if info.Mode()&0200 == 0 {
 		err := os.Chmod(dir, 0755)
-		if err == nil {
+		if !s.ignorePerms && err == nil {
 			defer func() {
 				err := os.Chmod(dir, info.Mode().Perm())
 				if err != nil {
@@ -117,7 +118,7 @@ func (s *sharedPullerState) tempFile() (io.WriterAt, error) {
 		// file that we're going to try to reuse. To handle that, we need to
 		// make sure we have write permissions on the file before opening it.
 		err := os.Chmod(s.tempName, 0644)
-		if err != nil {
+		if !s.ignorePerms && err != nil {
 			s.failLocked("dst create chmod", err)
 			return nil, err
 		}

+ 2 - 2
test/util.go

@@ -93,7 +93,7 @@ func generateFiles(dir string, files, maxexp int, srcname string) error {
 		}
 
 		err = os.Chmod(p1, os.FileMode(rand.Intn(0777)|0400))
-		if err != nil {
+		if !ignorePerms && err != nil {
 			return err
 		}
 
@@ -152,7 +152,7 @@ func alterFiles(dir string) error {
 			if info.Mode()&0200 != 0200 {
 				// Not owner writable. Fix.
 				err = os.Chmod(path, 0644)
-				if err != nil {
+				if !ignorePerms && err != nil {
 					return err
 				}
 			}