mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 00:43:49 +01:00
local: Implement -x/--one-file-system to stay on a single file system
This commit is contained in:
parent
2302179237
commit
15c9fed60f
@ -12,6 +12,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
@ -19,8 +20,11 @@ import (
|
||||
|
||||
"github.com/ncw/rclone/fs"
|
||||
"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
|
||||
func init() {
|
||||
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))
|
||||
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() {
|
||||
err := fd.Close()
|
||||
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) {
|
||||
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})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user