From 540fd3f173d47a6a96df0ab448e74543f645ba75 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 4 Jan 2020 18:02:32 +0000 Subject: [PATCH] local: fix update of hidden files on Windows - fixes #3839 --- backend/local/local.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/local/local.go b/backend/local/local.go index 12e52b31d..e67443e07 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -956,7 +956,17 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op if !o.translatedLink { f, err := file.OpenFile(o.path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { - return err + if runtime.GOOS == "windows" && os.IsPermission(err) { + // If permission denied on Windows might be trying to update a + // hidden file, in which case try opening without CREATE + // See: https://stackoverflow.com/questions/13215716/ioerror-errno-13-permission-denied-when-trying-to-open-hidden-file-in-w-mod + f, err = file.OpenFile(o.path, os.O_WRONLY|os.O_TRUNC, 0666) + if err != nil { + return err + } + } else { + return err + } } // Pre-allocate the file for performance reasons err = preAllocate(src.Size(), f)