mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/fs: rename SymlinkRelative to MustSymlinkRelative
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
5f487ed996
commit
780abc3b3b
2 changed files with 12 additions and 13 deletions
10
lib/fs/fs.go
10
lib/fs/fs.go
|
@ -288,14 +288,16 @@ func IsDirOrSymlink(de os.DirEntry) bool {
|
|||
return de.IsDir() || (de.Type()&os.ModeSymlink == os.ModeSymlink)
|
||||
}
|
||||
|
||||
// SymlinkRelative creates relative symlink for srcPath in dstPath.
|
||||
func SymlinkRelative(srcPath, dstPath string) error {
|
||||
// MustSymlinkRelative creates relative symlink for srcPath in dstPath.
|
||||
func MustSymlinkRelative(srcPath, dstPath string) {
|
||||
baseDir := filepath.Dir(dstPath)
|
||||
srcPathRel, err := filepath.Rel(baseDir, srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot make relative path for srcPath=%q: %w", srcPath, err)
|
||||
logger.Panicf("FATAL: cannot make relative path for srcPath=%q: %s", srcPath, err)
|
||||
}
|
||||
if err := os.Symlink(srcPathRel, dstPath); err != nil {
|
||||
logger.Panicf("FATAL: cannot make a symlink: %s", err)
|
||||
}
|
||||
return os.Symlink(srcPathRel, dstPath)
|
||||
}
|
||||
|
||||
// CopyDirectory copies all the files in srcPath to dstPath.
|
||||
|
|
|
@ -330,14 +330,13 @@ func (s *Storage) CreateSnapshot(deadline uint64) (string, error) {
|
|||
|
||||
dstDataDir := filepath.Join(dstDir, dataDirname)
|
||||
fs.MustMkdirFailIfExist(dstDataDir)
|
||||
|
||||
dstSmallDir := filepath.Join(dstDataDir, smallDirname)
|
||||
if err := fs.SymlinkRelative(smallDir, dstSmallDir); err != nil {
|
||||
return "", fmt.Errorf("cannot create symlink from %q to %q: %w", smallDir, dstSmallDir, err)
|
||||
}
|
||||
fs.MustSymlinkRelative(smallDir, dstSmallDir)
|
||||
|
||||
dstBigDir := filepath.Join(dstDataDir, bigDirname)
|
||||
if err := fs.SymlinkRelative(bigDir, dstBigDir); err != nil {
|
||||
return "", fmt.Errorf("cannot create symlink from %q to %q: %w", bigDir, dstBigDir, err)
|
||||
}
|
||||
fs.MustSymlinkRelative(bigDir, dstBigDir)
|
||||
|
||||
fs.MustSyncPath(dstDataDir)
|
||||
|
||||
srcMetadataDir := filepath.Join(srcDir, metadataDirname)
|
||||
|
@ -362,9 +361,7 @@ func (s *Storage) CreateSnapshot(deadline uint64) (string, error) {
|
|||
return "", fmt.Errorf("cannot create prev indexDB snapshot: %w", err)
|
||||
}
|
||||
dstIdbDir := filepath.Join(dstDir, indexdbDirname)
|
||||
if err := fs.SymlinkRelative(idbSnapshot, dstIdbDir); err != nil {
|
||||
return "", fmt.Errorf("cannot create symlink from %q to %q: %w", idbSnapshot, dstIdbDir, err)
|
||||
}
|
||||
fs.MustSymlinkRelative(idbSnapshot, dstIdbDir)
|
||||
|
||||
fs.MustSyncPath(dstDir)
|
||||
|
||||
|
|
Loading…
Reference in a new issue