forked from TrueCloudLab/rclone
local: Implement -x/--one-file-system to stay on a single file system
This commit is contained in:
parent
2302179237
commit
15c9fed60f
1 changed files with 14 additions and 1 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
@ -19,8 +20,11 @@ import (
|
||||||
|
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var oneFileSystem = pflag.BoolP("one-file-system", "x", false, "Don't cross filesystem boundaries.")
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fsi := &fs.RegInfo{
|
fsi := &fs.RegInfo{
|
||||||
|
@ -151,6 +155,15 @@ func (f *Fs) list(out fs.ListOpts, remote string, dirpath string, level int) (su
|
||||||
out.SetError(errors.Wrapf(err, "failed to open directory %q", dirpath))
|
out.SetError(errors.Wrapf(err, "failed to open directory %q", dirpath))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtain dirpath's device
|
||||||
|
fdFi, err := os.Stat(dirpath)
|
||||||
|
if err != nil {
|
||||||
|
out.SetError(errors.Wrapf(err, "failed to stat directory %q", dirpath))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
fdDev := fdFi.Sys().(*syscall.Stat_t).Dev
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err := fd.Close()
|
err := fd.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -186,7 +199,7 @@ func (f *Fs) list(out fs.ListOpts, remote string, dirpath string, level int) (su
|
||||||
if out.AddDir(dir) {
|
if out.AddDir(dir) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if level > 0 {
|
if level > 0 && !(*oneFileSystem && !((fi.Sys().(*syscall.Stat_t)).Dev == fdDev)) {
|
||||||
subdirs = append(subdirs, listArgs{remote: newRemote, dirpath: newPath, level: level - 1})
|
subdirs = append(subdirs, listArgs{remote: newRemote, dirpath: newPath, level: level - 1})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue