"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
local: factor PreAllocate and SetSparse to lib/file
Nick Craig-Wood36d2c46bcf81
diff --git a/backend/local/local.go b/backend/local/local.goindex 5e5369e74..8d2128292 100644--- a/backend/local/local.go+++ b/backend/local/local.go@@ -977,7 +977,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op}}// Pre-allocate the file for performance reasons- err = preAllocate(src.Size(), f)+ err = file.PreAllocate(src.Size(), f)if err != nil {fs.Debugf(o, "Failed to pre-allocate: %v", err)}@@ -1064,12 +1064,12 @@ func (f *Fs) OpenWriterAt(ctx context.Context, remote string, size int64) (fs.Wrreturn nil, err}// Pre-allocate the file for performance reasons- err = preAllocate(size, out)+ err = file.PreAllocate(size, out)if err != nil {fs.Debugf(o, "Failed to pre-allocate: %v", err)}// Set the file to be a sparse file (important on Windows)- err = setSparse(out)+ err = file.SetSparse(out)if err != nil {fs.Debugf(o, "Failed to set sparse: %v", err)}diff --git a/backend/local/preallocate_other.go b/backend/local/preallocate_other.godeleted file mode 100644index 5738b485c..000000000--- a/backend/local/preallocate_other.go+++ /dev/null@@ -1,15 +0,0 @@-//+build !windows,!linux--package local--import "os"--// preAllocate the file for performance reasons-func preAllocate(size int64, out *os.File) error {- return nil-}--// setSparse makes the file be a sparse file-func setSparse(out *os.File) error {- return nil-}diff --git a/lib/file/preallocate_other.go b/lib/file/preallocate_other.gonew file mode 100644index 000000000..5eae4ceab--- /dev/null+++ b/lib/file/preallocate_other.go@@ -0,0 +1,15 @@+//+build !windows,!linux++package file++import "os"++// PreAllocate the file for performance reasons+func PreAllocate(size int64, out *os.File) error {+ return nil+}++// SetSparse makes the file be a sparse file+func SetSparse(out *os.File) error {+ return nil+}diff --git a/backend/local/preallocate_unix.go b/lib/file/preallocate_unix.gosimilarity index 82%rename from backend/local/preallocate_unix.gorename to lib/file/preallocate_unix.goindex e7472f6a7..0bdd25ee5 100644--- a/backend/local/preallocate_unix.go+++ b/lib/file/preallocate_unix.go@@ -1,6 +1,6 @@//+build linux-package local+package fileimport ("os"@@ -18,8 +18,8 @@ var (fallocFlagsIndex int32)-// preAllocate the file for performance reasons-func preAllocate(size int64, out *os.File) error {+// PreAllocate the file for performance reasons+func PreAllocate(size int64, out *os.File) error {if size <= 0 {return nil}@@ -45,7 +45,7 @@ again:return err}-// setSparse makes the file be a sparse file-func setSparse(out *os.File) error {+// SetSparse makes the file be a sparse file+func SetSparse(out *os.File) error {return nil}diff --git a/backend/local/preallocate_windows.go b/lib/file/preallocate_windows.gosimilarity index 91%rename from backend/local/preallocate_windows.gorename to lib/file/preallocate_windows.goindex a434272f7..f956536f7 100644--- a/backend/local/preallocate_windows.go+++ b/lib/file/preallocate_windows.go@@ -1,6 +1,6 @@//+build windows-package local+package fileimport ("os"@@ -32,8 +32,8 @@ type ioStatusBlock struct {Status, Information uintptr}-// preAllocate the file for performance reasons-func preAllocate(size int64, out *os.File) error {+// PreAllocate the file for performance reasons+func PreAllocate(size int64, out *os.File) error {if size <= 0 {return nil}@@ -82,8 +82,8 @@ const (FSCTL_SET_SPARSE = 0x000900c4)-// setSparse makes the file be a sparse file-func setSparse(out *os.File) error {+// SetSparse makes the file be a sparse file+func SetSparse(out *os.File) error {err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), FSCTL_SET_SPARSE, nil, 0, nil, 0, nil, nil)if err != nil {return errors.Wrap(err, "DeviceIoControl FSCTL_SET_SPARSE")