Make targets writeable before removal on Windows (fixes #1610)

This commit is contained in:
Audrius Butkevicius
2015-04-16 22:07:04 +01:00
parent c6300a5da8
commit dff51fc707
3 changed files with 115 additions and 6 deletions

View File

@@ -88,6 +88,20 @@ func InWritableDir(fn func(string) error, path string) error {
return fn(path)
}
// On Windows, removes the read-only attribute from the target prior deletion.
func Remove(path string) error {
if runtime.GOOS == "windows" {
info, err := os.Stat(path)
if err != nil {
return err
}
if info.Mode()&0200 == 0 {
os.Chmod(path, 0700)
}
}
return os.Remove(path)
}
func ExpandTilde(path string) (string, error) {
if path == "~" {
return getHomeDir()