diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 726a123de..5c4bb3ed4 100644 --- a/lib/fs/fs.go +++ b/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. diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 3c7277ef0..d7dbcef5f 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -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)