lib/fs: rename HardLinkFiles to MustHardLinkFiles

Callers of this function log the returned error and then exit.
Let's log the error with the call stack inside the function itself.
This simplifies the code at callers' side, while leaving the same
level of debuggability in case of errors.
This commit is contained in:
Aliaksandr Valialkin 2023-04-13 22:48:05 -07:00
parent 30425ca81a
commit 5f487ed996
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
3 changed files with 6 additions and 11 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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.