diff --git a/lib/fs/fs.go b/lib/fs/fs.go index c86eef233..726a123de 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -259,13 +259,13 @@ func MustRemoveTemporaryDirs(dir string) { MustSyncPath(dir) } -// HardLinkFiles makes hard links for all the files from srcDir in dstDir. -func HardLinkFiles(srcDir, dstDir string) error { +// MustHardLinkFiles makes hard links for all the files from srcDir in dstDir. +func MustHardLinkFiles(srcDir, dstDir string) { mustMkdirSync(dstDir) des, err := os.ReadDir(srcDir) if err != nil { - return fmt.Errorf("cannot read files in scrDir: %w", err) + logger.Panicf("FATAL: cannot read files in scrDir: %s", err) } for _, de := range des { if IsDirOrSymlink(de) { @@ -276,12 +276,11 @@ func HardLinkFiles(srcDir, dstDir string) error { srcPath := filepath.Join(srcDir, fn) dstPath := filepath.Join(dstDir, fn) if err := os.Link(srcPath, dstPath); err != nil { - return err + logger.Panicf("FATAL: cannot link files: %s", err) } } MustSyncPath(dstDir) - return nil } // IsDirOrSymlink returns true if de is directory or symlink. diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index 2c57add62..96a02ce7f 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -1477,9 +1477,7 @@ func (tb *Table) CreateSnapshotAt(dstDir string, deadline uint64) error { } srcPartPath := pw.p.path dstPartPath := filepath.Join(dstDir, filepath.Base(srcPartPath)) - if err := fs.HardLinkFiles(srcPartPath, dstPartPath); err != nil { - return fmt.Errorf("cannot create hard links from %q to %q: %w", srcPartPath, dstPartPath, err) - } + fs.MustHardLinkFiles(srcPartPath, dstPartPath) } fs.MustSyncPath(dstDir) diff --git a/lib/storage/partition.go b/lib/storage/partition.go index 096eeb593..5761a5473 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -1897,9 +1897,7 @@ func (pt *partition) createSnapshot(srcDir, dstDir string, pws []*partWrapper) e for _, pw := range pws { srcPartPath := pw.p.path dstPartPath := filepath.Join(dstDir, filepath.Base(srcPartPath)) - if err := fs.HardLinkFiles(srcPartPath, dstPartPath); err != nil { - return fmt.Errorf("cannot create hard links from %q to %q: %w", srcPartPath, dstPartPath, err) - } + fs.MustHardLinkFiles(srcPartPath, dstPartPath) } // Copy the appliedRetentionFilename to dstDir.