mirror of
https://github.com/rclone/rclone
synced 2024-12-22 13:03:02 +01:00
jottacloud: refactor all file state checks into common functions
This commit is contained in:
parent
b0f06d9920
commit
b389b84685
@ -807,15 +807,8 @@ func (f *Fs) newObjectWithInfo(ctx context.Context, remote string, info *api.Jot
|
|||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
if info != nil {
|
if info != nil {
|
||||||
if info.State != "COMPLETED" {
|
if !f.validFile(info) {
|
||||||
return nil, fs.ErrorObjectNotFound // File is incomplete or corrupt
|
return nil, fs.ErrorObjectNotFound
|
||||||
}
|
|
||||||
if o.fs.opt.TrashedOnly {
|
|
||||||
if !info.Deleted {
|
|
||||||
return nil, fs.ErrorObjectNotFound // Regular file but TrashedOnly
|
|
||||||
}
|
|
||||||
} else if bool(info.Deleted) {
|
|
||||||
return nil, fs.ErrorObjectNotFound // Deleted file and not TrashedOnly
|
|
||||||
}
|
}
|
||||||
err = o.setMetaData(info) // sets the info
|
err = o.setMetaData(info) // sets the info
|
||||||
} else {
|
} else {
|
||||||
@ -889,38 +882,28 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
return nil, errors.Wrap(err, "couldn't list files")
|
return nil, errors.Wrap(err, "couldn't list files")
|
||||||
}
|
}
|
||||||
|
|
||||||
if bool(result.Deleted) && !f.opt.TrashedOnly {
|
if !f.validFolder(&result) {
|
||||||
return nil, fs.ErrorDirNotFound
|
return nil, fs.ErrorDirNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range result.Folders {
|
for i := range result.Folders {
|
||||||
item := &result.Folders[i]
|
item := &result.Folders[i]
|
||||||
if !f.opt.TrashedOnly && bool(item.Deleted) {
|
if f.validFolder(item) {
|
||||||
continue
|
|
||||||
}
|
|
||||||
remote := path.Join(dir, f.opt.Enc.ToStandardName(item.Name))
|
remote := path.Join(dir, f.opt.Enc.ToStandardName(item.Name))
|
||||||
d := fs.NewDir(remote, time.Time(item.ModifiedAt))
|
d := fs.NewDir(remote, time.Time(item.ModifiedAt))
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i := range result.Files {
|
for i := range result.Files {
|
||||||
item := &result.Files[i]
|
item := &result.Files[i]
|
||||||
if f.opt.TrashedOnly {
|
if f.validFile(item) {
|
||||||
if !item.Deleted || item.State != "COMPLETED" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if item.Deleted || item.State != "COMPLETED" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
remote := path.Join(dir, f.opt.Enc.ToStandardName(item.Name))
|
remote := path.Join(dir, f.opt.Enc.ToStandardName(item.Name))
|
||||||
o, err := f.newObjectWithInfo(ctx, remote, item)
|
if o, err := f.newObjectWithInfo(ctx, remote, item); err == nil {
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
entries = append(entries, o)
|
entries = append(entries, o)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return entries, nil
|
return entries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -936,7 +919,7 @@ func (f *Fs) listFileDir(ctx context.Context, remoteStartPath string, startFolde
|
|||||||
startPathLength := len(startPath)
|
startPathLength := len(startPath)
|
||||||
for i := range startFolder.Folders {
|
for i := range startFolder.Folders {
|
||||||
folder := &startFolder.Folders[i]
|
folder := &startFolder.Folders[i]
|
||||||
if folder.Deleted {
|
if !f.validFolder(folder) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
folderPath := f.opt.Enc.ToStandardPath(path.Join(folder.Path, folder.Name))
|
folderPath := f.opt.Enc.ToStandardPath(path.Join(folder.Path, folder.Name))
|
||||||
@ -954,9 +937,7 @@ func (f *Fs) listFileDir(ctx context.Context, remoteStartPath string, startFolde
|
|||||||
}
|
}
|
||||||
for i := range folder.Files {
|
for i := range folder.Files {
|
||||||
file := &folder.Files[i]
|
file := &folder.Files[i]
|
||||||
if file.Deleted || file.State != "COMPLETED" {
|
if f.validFile(file) {
|
||||||
continue
|
|
||||||
}
|
|
||||||
remoteFile := path.Join(remoteDir, f.opt.Enc.ToStandardName(file.Name))
|
remoteFile := path.Join(remoteDir, f.opt.Enc.ToStandardName(file.Name))
|
||||||
o, err := f.newObjectWithInfo(ctx, remoteFile, file)
|
o, err := f.newObjectWithInfo(ctx, remoteFile, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -968,6 +949,7 @@ func (f *Fs) listFileDir(ctx context.Context, remoteStartPath string, startFolde
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1375,6 +1357,25 @@ func (o *Object) MimeType(ctx context.Context) string {
|
|||||||
return o.mimeType
|
return o.mimeType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validFile checks if info indicates file is valid
|
||||||
|
func (f *Fs) validFile(info *api.JottaFile) bool {
|
||||||
|
if info.State != "COMPLETED" {
|
||||||
|
return false // File is incomplete or corrupt
|
||||||
|
}
|
||||||
|
if !info.Deleted {
|
||||||
|
return !f.opt.TrashedOnly // Regular file; return false if TrashedOnly, else true
|
||||||
|
}
|
||||||
|
return f.opt.TrashedOnly // Deleted file; return true if TrashedOnly, else false
|
||||||
|
}
|
||||||
|
|
||||||
|
// validFolder checks if info indicates folder is valid
|
||||||
|
func (f *Fs) validFolder(info *api.JottaFolder) bool {
|
||||||
|
// Returns true if folder is not deleted.
|
||||||
|
// If TrashedOnly option then always returns true, because a folder not
|
||||||
|
// in trash must be traversed to get to files/subfolders that are.
|
||||||
|
return !bool(info.Deleted) || f.opt.TrashedOnly
|
||||||
|
}
|
||||||
|
|
||||||
// setMetaData sets the metadata from info
|
// setMetaData sets the metadata from info
|
||||||
func (o *Object) setMetaData(info *api.JottaFile) (err error) {
|
func (o *Object) setMetaData(info *api.JottaFile) (err error) {
|
||||||
o.hasMetaData = true
|
o.hasMetaData = true
|
||||||
@ -1394,15 +1395,8 @@ func (o *Object) readMetaData(ctx context.Context, force bool) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if info.State != "COMPLETED" {
|
if !o.fs.validFile(info) {
|
||||||
return fs.ErrorObjectNotFound // File is incomplete or corrupt
|
return fs.ErrorObjectNotFound
|
||||||
}
|
|
||||||
if o.fs.opt.TrashedOnly {
|
|
||||||
if !info.Deleted {
|
|
||||||
return fs.ErrorObjectNotFound // Regular file but TrashedOnly
|
|
||||||
}
|
|
||||||
} else if bool(info.Deleted) {
|
|
||||||
return fs.ErrorObjectNotFound // Deleted file and not TrashedOnly
|
|
||||||
}
|
}
|
||||||
return o.setMetaData(info)
|
return o.setMetaData(info)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user