Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

truncate file content during creating

Chris Lue6e85a6b2cb1
diff --git a/go/storage/volume.go b/go/storage/volume.go
index 59c3055e3c..69817a6d4d 100644
--- a/go/storage/volume.go
+++ b/go/storage/volume.go
@@ -370,12 +370,12 @@ func (v *Volume) copyDataAndGenerateIndexFile(dstName, idxName string) (err erro
var (
dst, idx *os.File
)
- if dst, err = os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE, 0644); err != nil {
+ if dst, err = os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
return
}
defer dst.Close()
- if idx, err = os.OpenFile(idxName, os.O_WRONLY|os.O_CREATE, 0644); err != nil {
+ if idx, err = os.OpenFile(idxName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
return
}
defer idx.Close()
diff --git a/go/weed/fix.go b/go/weed/fix.go
index 159e2dbde9..3c09727c19 100644
--- a/go/weed/fix.go
+++ b/go/weed/fix.go
@@ -37,7 +37,7 @@ func runFix(cmd *Command, args []string) bool {
if *fixVolumeCollection != "" {
fileName = *fixVolumeCollection + "_" + fileName
}
- indexFile, err := os.OpenFile(path.Join(*fixVolumePath, fileName+".idx"), os.O_WRONLY|os.O_CREATE, 0644)
+ indexFile, err := os.OpenFile(path.Join(*fixVolumePath, fileName+".idx"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
glog.Fatalf("Create Volume Index [ERROR] %s\n", err)
}