From 40b58d59ad59e34c1393dcc6a8f122e4458932f9 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 17 Feb 2021 13:05:15 +0000 Subject: [PATCH] lib/file: make pre-allocate detect disk full errors and return them --- lib/file/preallocate.go | 6 ++++++ lib/file/preallocate_unix.go | 8 ++++---- lib/file/preallocate_windows.go | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 lib/file/preallocate.go diff --git a/lib/file/preallocate.go b/lib/file/preallocate.go new file mode 100644 index 000000000..a87c26b20 --- /dev/null +++ b/lib/file/preallocate.go @@ -0,0 +1,6 @@ +package file + +import "errors" + +// ErrDiskFull is returned from PreAllocate when it detects disk full +var ErrDiskFull = errors.New("preallocate: file too big for remaining disk space") diff --git a/lib/file/preallocate_unix.go b/lib/file/preallocate_unix.go index 8c3df5238..c44c869ea 100644 --- a/lib/file/preallocate_unix.go +++ b/lib/file/preallocate_unix.go @@ -42,10 +42,10 @@ again: goto again } - // FIXME could be doing something here - // if err == unix.ENOSPC { - // log.Printf("No space") - // } + // Wrap important errors + if err == unix.ENOSPC { + return ErrDiskFull + } return err } diff --git a/lib/file/preallocate_windows.go b/lib/file/preallocate_windows.go index f92f9f7f7..847a49a48 100644 --- a/lib/file/preallocate_windows.go +++ b/lib/file/preallocate_windows.go @@ -76,6 +76,9 @@ func PreAllocate(size int64, out *os.File) error { uintptr(19), // FileAllocationInformation ) if e1 != nil && e1 != syscall.Errno(0) { + if e1 == syscall.Errno(windows.ERROR_DISK_FULL) || e1 == syscall.Errno(windows.ERROR_HANDLE_DISK_FULL) { + return ErrDiskFull + } return errors.Wrap(e1, "preAllocate NtSetInformationFile failed") }