Skip to content

Commit f2ce7ad

Browse files
committed
Fix reviewdog suggestions
1 parent 6dd48af commit f2ce7ad

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

pbm/restore/physical.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (r *PhysRestore) close(noerr, cleanup bool) {
242242
}
243243

244244
if cStatus == defs.StatusError {
245-
err := r.migrateFromFallbackDirToDbDir()
245+
err := r.migrateFromFallbackDirToDBDir()
246246
if err != nil {
247247
r.log.Error("migrate from fallback dir: %v", err)
248248
}
@@ -349,17 +349,17 @@ func (r *PhysRestore) flush(ctx context.Context) error {
349349
}
350350
}
351351

352-
err = r.migrateDbDirToFallbackDir()
352+
err = r.migrateDBDirToFallbackDir()
353353
if err != nil {
354354
return errors.Wrapf(err, "move files to fallback path")
355355
}
356356

357357
return nil
358358
}
359359

360-
// migrateDbDirToFallbackDir moves content of dbPath dir into fallback dir.
360+
// migrateDBDirToFallbackDir moves content of dbPath dir into fallback dir.
361361
// It also removes old fallback dir, and creates new with the same perms.
362-
func (r *PhysRestore) migrateDbDirToFallbackDir() error {
362+
func (r *PhysRestore) migrateDBDirToFallbackDir() error {
363363
dbpath := filepath.Clean(r.dbpath)
364364
fallbackPath := filepath.Join(dbpath, fallbackDir)
365365
r.log.Debug("dbpath: %s, fallbackPath: %s", dbpath, fallbackPath)
@@ -388,19 +388,21 @@ func (r *PhysRestore) migrateDbDirToFallbackDir() error {
388388
return nil
389389
}
390390

391-
// migrateFromFallbackDirToDbDir wipe up dbpath dir and
391+
// migrateFromFallbackDirToDBDir wipe up dbpath dir and
392392
// moves all content from fallback path.
393-
func (r *PhysRestore) migrateFromFallbackDirToDbDir() error {
393+
func (r *PhysRestore) migrateFromFallbackDirToDBDir() error {
394394
r.log.Debug("clean-up dbpath")
395395
err := removeAll(r.dbpath, []string{fallbackDir}, r.log)
396396
if err != nil {
397397
r.log.Error("flush dbpath %s: %v", r.dbpath, err)
398+
return errors.Wrap(err, "remove all from dbpath")
398399
}
399400

400401
r.log.Info("move data files from %s to %s", fallbackDir, r.dbpath)
401402
err = r.moveFromFallback()
402403
if err != nil {
403404
r.log.Error("moving from %s: %v", fallbackDir, err)
405+
return errors.Wrapf(err, "move from %s", fallbackDir)
404406
}
405407

406408
return nil
@@ -2483,13 +2485,15 @@ func (r *PhysRestore) MarkFailed(meta *RestoreMeta, e error) {
24832485
// (in `toState` method).
24842486
// Here we are not aware of partlyDone etc so leave it to the `toState`.
24852487
if r.checkForRSLevelErr() {
2488+
r.log.Debug("set error on rs level")
24862489
serr := util.RetryableWrite(r.stg,
24872490
r.syncPathRS+"."+string(defs.StatusError), errStatus(e))
24882491
if serr != nil {
24892492
r.log.Error("MarkFailed: write replset error state `%v`: %v", e, serr)
24902493
}
24912494
}
24922495
if r.nodeInfo.IsLeader() && r.checkForClusterLevelErr() {
2496+
r.log.Debug("set error on cluster level")
24932497
serr := util.RetryableWrite(r.stg,
24942498
r.syncPathCluster+"."+string(defs.StatusError), errStatus(e))
24952499
if serr != nil {

pbm/restore/physical_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func TestMoveAll(t *testing.T) {
2222
for i, file := range testFiles {
2323
_ = os.WriteFile(
2424
filepath.Join(tempSrc, file),
25-
[]byte(fmt.Sprintf("test content %d", i)), 0644)
25+
[]byte(fmt.Sprintf("test content %d", i)), 0o644)
2626
}
2727

2828
subDir := filepath.Join(tempSrc, "subdir")
29-
_ = os.Mkdir(subDir, 0755)
29+
_ = os.Mkdir(subDir, 0o755)
3030

3131
err := moveAll(tempSrc, tempDst, nil, log.DiscardLogger.NewDefaultEvent())
3232
if err != nil {
@@ -63,11 +63,11 @@ func TestMoveAll(t *testing.T) {
6363
for i, file := range testFiles {
6464
_ = os.WriteFile(
6565
filepath.Join(tempSrc, file),
66-
[]byte(fmt.Sprintf("test content %d", i)), 0644)
66+
[]byte(fmt.Sprintf("test content %d", i)), 0o644)
6767
}
6868

69-
_ = os.Mkdir(filepath.Join(tempSrc, "ignore_dir"), 0755)
70-
_ = os.Mkdir(filepath.Join(tempSrc, "normal_dir"), 0755)
69+
_ = os.Mkdir(filepath.Join(tempSrc, "ignore_dir"), 0o755)
70+
_ = os.Mkdir(filepath.Join(tempSrc, "normal_dir"), 0o755)
7171

7272
toIgnore := []string{"ignore_me", "ignore_dir"}
7373

@@ -122,13 +122,12 @@ func TestMoveAll(t *testing.T) {
122122
tempDst, _ := os.MkdirTemp("", "dst")
123123
defer os.RemoveAll(tempDst)
124124

125-
_ = os.Chmod(tempDst, 0500) // read-only
126-
defer os.Chmod(tempDst, 0700) // Restore permissions for cleanup
125+
_ = os.Chmod(tempDst, 0o400)
127126

128127
// Create test file in source
129128
_ = os.WriteFile(
130129
filepath.Join(tempSrc, "test"),
131-
[]byte("test content"), 0644)
130+
[]byte("test content"), 0o644)
132131

133132
err := moveAll(tempSrc, tempDst, nil, log.DiscardLogger.NewDefaultEvent())
134133
if err == nil {

0 commit comments

Comments
 (0)