6a7 > "io/fs" 7a9 > "path/filepath" 44c46 < // RemoveAll removes the named file or (empty) directory with at most 5 attempts. --- > // RemoveAll removes the named file or directory with at most 5 attempts. 46a49 > 47a51,82 > // Do chmod -R +w to help ensure the removal succeeds. > // In particular, in the git-annex case, this handles > // https://git-annex.branchable.com/internals/lockdown/ : > // > // > (The only bad consequence of this is that rm -rf .git > // > doesn't work unless you first run chmod -R +w .git) > > err = filepath.WalkDir(name, func(path string, d fs.DirEntry, err error) error { > // NB: this is called WalkDir but it works on a single file too > if err == nil { > info, err := d.Info() > if err != nil { > return err > } > > // Don't try chmod'ing symlinks (will fail with broken symlinks) > if info.Mode()&os.ModeSymlink != os.ModeSymlink { > // 0200 == u+w, in octal unix permission notation > err = os.Chmod(path, info.Mode()|0o200) > if err != nil { > return err > } > } > } > return nil > }) > if err != nil { > // try again > <-time.After(100 * time.Millisecond) > continue > } >