MCPcopy
hub / github.com/git-lfs/git-lfs / SetFileWriteFlag

Function SetFileWriteFlag

tools/filetools.go:435–455  ·  view source on GitHub ↗

SetFileWriteFlag changes write permissions on a file Used to make a file read-only or not. When writeEnabled = false, the write bit is removed for all roles. When writeEnabled = true, the behaviour is different per platform: On Mac & Linux, the write bit is set only on the owner as per default umask

(path string, writeEnabled bool)

Source from the content-addressed store, hash-verified

433// All other bits are unaffected.
434// On Windows, all the write bits are set since Windows doesn't support Unix permissions.
435func SetFileWriteFlag(path string, writeEnabled bool) error {
436 stat, err := os.Stat(path)
437 if err != nil {
438 return err
439 }
440 mode := uint32(stat.Mode())
441
442 if (writeEnabled && (mode&0200) > 0) ||
443 (!writeEnabled && (mode&0222) == 0) {
444 // no change needed
445 return nil
446 }
447
448 if writeEnabled {
449 mode = mode | 0200 // set owner write only
450 // Go's own Chmod makes Windows set all though
451 } else {
452 mode = mode &^ 0222 // disable all write
453 }
454 return os.Chmod(path, os.FileMode(mode))
455}
456
457// TempFile creates a temporary file in specified directory with proper permissions for the repository.
458// On success, it returns an open, non-nil *os.File, and the caller is responsible

Callers 4

LockFileMethod · 0.92
UnlockFileByIdMethod · 0.92
TestSetWriteFlagFunction · 0.85

Calls 1

ModeMethod · 0.80

Tested by 1

TestSetWriteFlagFunction · 0.68