2015-07-18 21:19:50 +00:00
|
|
|
// +build !openbsd
|
2015-08-14 13:33:11 +00:00
|
|
|
// +build !windows
|
2015-07-18 21:19:50 +00:00
|
|
|
|
2015-04-07 19:10:53 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 19:59:13 +00:00
|
|
|
resticfs "restic/fs"
|
2016-02-14 14:29:28 +00:00
|
|
|
"restic/fuse"
|
2015-04-07 19:10:53 +00:00
|
|
|
|
2015-07-19 12:28:11 +00:00
|
|
|
systemFuse "bazil.org/fuse"
|
2015-04-07 19:10:53 +00:00
|
|
|
"bazil.org/fuse/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CmdMount struct {
|
2015-07-26 18:41:29 +00:00
|
|
|
Root bool `long:"owner-root" description:"use 'root' as the owner of files and dirs" default:"false"`
|
|
|
|
|
2015-04-07 19:10:53 +00:00
|
|
|
global *GlobalOptions
|
2015-07-18 19:31:34 +00:00
|
|
|
ready chan struct{}
|
2015-07-19 21:02:48 +00:00
|
|
|
done chan struct{}
|
2015-04-07 19:10:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
_, err := parser.AddCommand("mount",
|
|
|
|
"mount a repository",
|
|
|
|
"The mount command mounts a repository read-only to a given directory",
|
2015-07-18 19:31:34 +00:00
|
|
|
&CmdMount{
|
|
|
|
global: &globalOpts,
|
|
|
|
ready: make(chan struct{}, 1),
|
2015-07-19 21:02:48 +00:00
|
|
|
done: make(chan struct{}),
|
2015-07-18 19:31:34 +00:00
|
|
|
})
|
2015-04-07 19:10:53 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd CmdMount) Usage() string {
|
|
|
|
return "MOUNTPOINT"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd CmdMount) Execute(args []string) error {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
|
|
|
|
}
|
|
|
|
|
|
|
|
repo, err := cmd.global.OpenRepository()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = repo.LoadIndex()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mountpoint := args[0]
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 19:59:13 +00:00
|
|
|
if _, err := resticfs.Stat(mountpoint); os.IsNotExist(err) {
|
2015-07-19 12:08:34 +00:00
|
|
|
cmd.global.Verbosef("Mountpoint %s doesn't exist, creating it\n", mountpoint)
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 19:59:13 +00:00
|
|
|
err = resticfs.Mkdir(mountpoint, os.ModeDir|0700)
|
2015-07-19 12:08:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-04-07 19:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 12:28:11 +00:00
|
|
|
c, err := systemFuse.Mount(
|
2015-04-07 19:10:53 +00:00
|
|
|
mountpoint,
|
2015-07-19 12:28:11 +00:00
|
|
|
systemFuse.ReadOnly(),
|
|
|
|
systemFuse.FSName("restic"),
|
2015-04-07 19:10:53 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
root := fs.Tree{}
|
2015-07-26 18:41:29 +00:00
|
|
|
root.Add("snapshots", fuse.NewSnapshotsDir(repo, cmd.Root))
|
2015-04-07 19:10:53 +00:00
|
|
|
|
2015-07-19 12:08:34 +00:00
|
|
|
cmd.global.Printf("Now serving %s at %s\n", repo.Backend().Location(), mountpoint)
|
|
|
|
cmd.global.Printf("Don't forget to umount after quitting!\n")
|
2015-04-07 19:10:53 +00:00
|
|
|
|
2015-07-19 21:02:02 +00:00
|
|
|
AddCleanupHandler(func() error {
|
|
|
|
return systemFuse.Unmount(mountpoint)
|
|
|
|
})
|
|
|
|
|
2015-07-18 19:31:34 +00:00
|
|
|
cmd.ready <- struct{}{}
|
|
|
|
|
2015-07-19 21:02:48 +00:00
|
|
|
errServe := make(chan error)
|
|
|
|
go func() {
|
|
|
|
err = fs.Serve(c, &root)
|
|
|
|
if err != nil {
|
|
|
|
errServe <- err
|
|
|
|
}
|
|
|
|
|
|
|
|
<-c.Ready
|
|
|
|
errServe <- c.MountError
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case err := <-errServe:
|
2015-04-07 19:10:53 +00:00
|
|
|
return err
|
2015-07-19 21:02:48 +00:00
|
|
|
case <-cmd.done:
|
2016-04-13 18:17:02 +00:00
|
|
|
err := systemFuse.Unmount(mountpoint)
|
2015-07-19 21:02:48 +00:00
|
|
|
if err != nil {
|
2016-04-13 18:17:02 +00:00
|
|
|
cmd.global.Printf("Error umounting: %s\n", err)
|
2015-07-19 21:02:48 +00:00
|
|
|
}
|
2016-04-13 18:17:02 +00:00
|
|
|
return c.Close()
|
2015-04-07 19:10:53 +00:00
|
|
|
}
|
|
|
|
}
|