diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6c129a3..5f29717 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,10 @@
-
+
-
+
+
@@ -97,8 +98,8 @@
-
-
+
+
@@ -118,7 +119,6 @@
-
@@ -143,7 +143,8 @@
-
+
+
true
diff --git a/pkg/internal/services/merger.go b/pkg/internal/services/merger.go
index cedea5d..1de36b7 100644
--- a/pkg/internal/services/merger.go
+++ b/pkg/internal/services/merger.go
@@ -27,7 +27,7 @@ func MergeFileChunks(meta models.Attachment, arrange []string) (models.Attachmen
// Merge files
for _, chunk := range arrange {
- chunkPath := filepath.Join(dest.Path, fmt.Sprintf("%s.%s", meta.Uuid, chunk))
+ chunkPath := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, chunk))
chunkFile, err := os.Open(chunkPath)
if err != nil {
return meta, err
@@ -52,7 +52,7 @@ func MergeFileChunks(meta models.Attachment, arrange []string) (models.Attachmen
// Clean up
for _, chunk := range arrange {
- chunkPath := filepath.Join(dest.Path, fmt.Sprintf("%s.%s", meta.Uuid, chunk))
+ chunkPath := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, chunk))
_ = os.Remove(chunkPath)
}
diff --git a/pkg/internal/services/recycler.go b/pkg/internal/services/recycler.go
index 2cd396c..e96701e 100644
--- a/pkg/internal/services/recycler.go
+++ b/pkg/internal/services/recycler.go
@@ -104,7 +104,7 @@ func DeleteFile(meta models.Attachment) error {
_ = jsoniter.Unmarshal(rawDest, &dest)
for cid := range meta.FileChunks {
- path := filepath.Join(dest.Path, fmt.Sprintf("%s.%s", meta.Uuid, cid))
+ path := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, cid))
_ = os.Remove(path)
}
diff --git a/pkg/internal/services/uploader.go b/pkg/internal/services/uploader.go
index 1f9963a..d1dbb99 100644
--- a/pkg/internal/services/uploader.go
+++ b/pkg/internal/services/uploader.go
@@ -46,7 +46,12 @@ func UploadChunkToTemporary(ctx *fiber.Ctx, cid string, file *multipart.FileHead
case models.DestinationTypeLocal:
var destConfigured models.LocalDestination
_ = jsoniter.Unmarshal(rawDest, &destConfigured)
- return ctx.SaveFile(file, filepath.Join(destConfigured.Path, fmt.Sprintf("%s.%s", meta.Uuid, cid)))
+ tempPath := filepath.Join(destConfigured.Path, fmt.Sprintf("%s.part%s.partial", meta.Uuid, cid))
+ destPath := filepath.Join(destConfigured.Path, fmt.Sprintf("%s.part%s", meta.Uuid, cid))
+ if err := ctx.SaveFile(file, tempPath); err != nil {
+ return err
+ }
+ return os.Rename(tempPath, destPath)
default:
return fmt.Errorf("invalid destination: unsupported protocol %s", dest.Type)
}
@@ -59,7 +64,7 @@ func CheckChunkExistsInTemporary(meta models.Attachment, cid string) bool {
rawDest, _ := jsoniter.Marshal(destMap)
_ = jsoniter.Unmarshal(rawDest, &dest)
- path := filepath.Join(dest.Path, fmt.Sprintf("%s.%s", meta.Uuid, cid))
+ path := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, cid))
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
return false
} else {