Skip to content

Commit

Permalink
mmove files across volumes inside 🐳
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsilvio committed Feb 21, 2024
1 parent 6b6515e commit 1fb242e
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions internal/data/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,13 @@ func ImportRevokedCertificate(in model.FileContentWithPath) error {
}

if err := os.Rename(sourcePath, targetPath); err != nil {
logger.Error("Failed to move file %v", err)

if strings.Contains(err.Error(), "cross-device") {
if err := moveHard(sourcePath, targetPath); err != nil {
return err
}
}

} else {
logger.Debug("Moved file to %s", targetPath)
}
Expand Down Expand Up @@ -494,7 +500,29 @@ func ArchiveRequest(path, file string) {
func Delete(path string) error {
err := os.Remove(path)
if err != nil {
logger.Error("%v", err)
return err
}
return nil
}

func moveHard(src string, dst string) error {
fin, err := os.Open(src)
if err != nil {
return err
}
defer fin.Close()

fout, err := os.Create(dst)
if err != nil {
return err
}
defer fout.Close()

_, err = io.Copy(fout, fin)
if err != nil {
return err
}

err = os.Remove(src)
return err
}

0 comments on commit 1fb242e

Please sign in to comment.