[lxc-devel] [lxd/master] lxd/storage: Fix regression in truncate handling
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Jun 30 20:17:42 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200630/37e1a1c8/attachment.bin>
-------------- next part --------------
From 7f28fe06cf7888589e8d4fdaa65d537490c45438 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 30 Jun 2020 16:17:27 -0400
Subject: [PATCH] lxd/storage: Fix regression in truncate handling
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/storage/drivers/utils.go | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go
index 988bf98208..d4539b693b 100644
--- a/lxd/storage/drivers/utils.go
+++ b/lxd/storage/drivers/utils.go
@@ -295,17 +295,12 @@ func deleteParentSnapshotDirIfEmpty(poolName string, volType VolumeType, volName
// ensureSparseFile creates a sparse empty file at specified location with specified size.
// If the path already exists, the file is truncated to the requested size.
func ensureSparseFile(filePath string, sizeBytes int64) error {
- f, err := os.Create(filePath)
+ f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return errors.Wrapf(err, "Failed to open %s", filePath)
}
defer f.Close()
- err = f.Chmod(0600)
- if err != nil {
- return errors.Wrapf(err, "Failed to chmod %s", filePath)
- }
-
err = f.Truncate(sizeBytes)
if err != nil {
return errors.Wrapf(err, "Failed to create sparse file %s", filePath)
More information about the lxc-devel
mailing list