From 520b1b65b0759b4823999512c1a8ee632277cf76 Mon Sep 17 00:00:00 2001
From: Klaus Post <klauspost@gmail.com>
Date: Sun, 16 Aug 2015 12:39:38 +0200
Subject: [PATCH] Create setNewFileMode function.

Create separate files with setNewFileMode to avoid
runtime checks.
---
 backend/local/local.go         | 12 +-----------
 backend/local/local_unix.go    | 12 ++++++++++++
 backend/local/local_windows.go | 12 ++++++++++++
 3 files changed, 25 insertions(+), 11 deletions(-)
 create mode 100644 backend/local/local_unix.go
 create mode 100644 backend/local/local_windows.go

diff --git a/backend/local/local.go b/backend/local/local.go
index f63a71743..6f5d9d976 100644
--- a/backend/local/local.go
+++ b/backend/local/local.go
@@ -7,7 +7,6 @@ import (
 	"io/ioutil"
 	"os"
 	"path/filepath"
-	"runtime"
 	"sort"
 	"sync"
 
@@ -147,16 +146,7 @@ func (lb *localBlob) Finalize(t backend.Type, name string) error {
 		return err
 	}
 
-	// set file to readonly, except on Windows,
-	// otherwise deletion will fail.
-	if runtime.GOOS != "windows" {
-		err = os.Chmod(f, fi.Mode()&os.FileMode(^uint32(0222)))
-		if err != nil {
-			return err
-		}
-	}
-
-	return nil
+	return setNewFileMode(f, fi)
 }
 
 // Create creates a new Blob. The data is available only after Finalize()
diff --git a/backend/local/local_unix.go b/backend/local/local_unix.go
new file mode 100644
index 000000000..8b8ecec69
--- /dev/null
+++ b/backend/local/local_unix.go
@@ -0,0 +1,12 @@
+// +build !windows
+
+package local
+
+import (
+	"os"
+)
+
+// set file to readonly
+func setNewFileMode(f string, fi os.FileInfo) error {
+	return os.Chmod(f, fi.Mode()&os.FileMode(^uint32(0222)))
+}
diff --git a/backend/local/local_windows.go b/backend/local/local_windows.go
new file mode 100644
index 000000000..73633fa3e
--- /dev/null
+++ b/backend/local/local_windows.go
@@ -0,0 +1,12 @@
+package local
+
+import (
+	"os"
+)
+
+// We don't modify read-only on windows,
+// since it will make us unable to delete the file,
+// and this isn't common practice on this platform.
+func setNewFileMode(f string, fi os.FileInfo) error {
+	return nil
+}