Handle readonly empty files in windows
This commit is contained in:
parent
eeb1aa5388
commit
d4be734c73
1 changed files with 12 additions and 4 deletions
|
@ -205,11 +205,19 @@ func (res *Restorer) restoreHardlinkAt(node *restic.Node, target, path, location
|
||||||
|
|
||||||
func (res *Restorer) restoreEmptyFileAt(node *restic.Node, target, location string) error {
|
func (res *Restorer) restoreEmptyFileAt(node *restic.Node, target, location string) error {
|
||||||
wr, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
wr, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
||||||
if err != nil {
|
if fs.IsAccessDenied(err) {
|
||||||
return err
|
// If file is readonly, clear the readonly flag by resetting the
|
||||||
|
// permissions of the file and try again
|
||||||
|
// as the metadata will be set again in the second pass and the
|
||||||
|
// readonly flag will be applied again if needed.
|
||||||
|
if err = fs.ResetPermissions(target); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if wr, err = os.OpenFile(target, os.O_TRUNC|os.O_WRONLY, 0600); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = wr.Close()
|
if err = wr.Close(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue