mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
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:
parent
30425ca81a
commit
5f487ed996
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user