mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
paths: skip unix chmod if state directory is already 0700
Updates #2934 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
3b3994f0db
commit
5263c8d0b5
@ -8,6 +8,7 @@
|
|||||||
package paths
|
package paths
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -62,10 +63,21 @@ func xdgDataHome() string {
|
|||||||
return filepath.Join(os.Getenv("HOME"), ".local/share")
|
return filepath.Join(os.Getenv("HOME"), ".local/share")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureStateDirPerms(dirPath string) error {
|
func ensureStateDirPerms(dir string) error {
|
||||||
if filepath.Base(dirPath) != "tailscale" {
|
if filepath.Base(dir) != "tailscale" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
fi, err := os.Stat(dir)
|
||||||
return os.Chmod(dirPath, 0700)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !fi.IsDir() {
|
||||||
|
return fmt.Errorf("expected %q to be a directory; is %v", dir, fi.Mode())
|
||||||
|
}
|
||||||
|
const perm = 0700
|
||||||
|
if fi.Mode().Perm() == perm {
|
||||||
|
// Already correct.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return os.Chmod(dir, perm)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user