forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b29581c
commit aa63669
Showing
10 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package perms | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// ChmodR sets the permissions of all directories and optionally files to [perm] | ||
// permissions. | ||
func ChmodR(dir string, dirOnly bool, perm os.FileMode) error { | ||
return filepath.Walk(dir, func(name string, info os.FileInfo, err error) error { | ||
if err != nil || (dirOnly && !info.IsDir()) { | ||
return err | ||
} | ||
return os.Chmod(name, perm) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package perms | ||
|
||
const ( | ||
ReadOnly = 0400 | ||
ReadWrite = 0600 | ||
ReadWriteExecute = 0700 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package perms | ||
|
||
import ( | ||
"errors" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
// WriteFile writes [data] to [filename] and ensures that [filename] has [perm] | ||
// permissions. | ||
func WriteFile(filename string, data []byte, perm os.FileMode) error { | ||
info, err := os.Stat(filename) | ||
if errors.Is(err, os.ErrNotExist) { | ||
// The file doesn't exist, so try to write it. | ||
return ioutil.WriteFile(filename, data, perm) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
if info.Mode() != perm { | ||
// The file currently has the wrong permissions, so update them. | ||
if err := os.Chmod(filename, perm); err != nil { | ||
return err | ||
} | ||
} | ||
// The file has the right permissions, so truncate any data and write the | ||
// file. | ||
return ioutil.WriteFile(filename, data, perm) | ||
} |