Skip to content

Commit

Permalink
Merge pull request #4590 from renard/optimize-mount-failure
Browse files Browse the repository at this point in the history
mount: detect mountpoint does not exist before opening the repository
  • Loading branch information
MichaelEischer committed Dec 24, 2023
2 parents 5537460 + f7587be commit 433dd92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/pull-4590
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: `mount` tests mountpoint existence before opening the repository

The restic `mount` command now checks for the existence of the
mountpoint before opening the repository, leading to quicker error
detection.

https://github.com/restic/restic/pull/4590
15 changes: 9 additions & 6 deletions cmd/restic/cmd_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args
return errors.Fatal("wrong number of parameters")
}

mountpoint := args[0]

// Check the existence of the mount point at the earliest stage to
// prevent unnecessary computations while opening the repository.
if _, err := resticfs.Stat(mountpoint); errors.Is(err, os.ErrNotExist) {
Verbosef("Mountpoint %s doesn't exist\n", mountpoint)
return err
}

debug.Log("start mount")
defer debug.Log("finish mount")

Expand All @@ -136,12 +145,6 @@ func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args
return err
}

mountpoint := args[0]

if _, err := resticfs.Stat(mountpoint); errors.Is(err, os.ErrNotExist) {
Verbosef("Mountpoint %s doesn't exist\n", mountpoint)
return err
}
mountOptions := []systemFuse.MountOption{
systemFuse.ReadOnly(),
systemFuse.FSName("restic"),
Expand Down

0 comments on commit 433dd92

Please sign in to comment.