Where should I add f.root to path?

I'm writing a new backend, but I don't know where to add f.root to path.
Take a look at these codes:
And there was a file /design-book.pdf in remote.

$ ls /home/*/source
design-book.pdf

$ ./rclone -vv copy /home/*/source test2:dest  
2020/05/24 09:36:47 DEBUG : rclone: Version "v1.51.0-DEV" starting with parameters ["./rclone" "-vv" "copy" "/home/*/source" "test2:dest"]
2020/05/24 09:36:47 DEBUG : Using config file from "/home/*/.config/rclone/rclone.conf"
2020/05/24 09:36:47 DEBUG : dest: NewFs
2020/05/24 09:36:47 DEBUG : Backend, root: dest: Features
2020/05/24 09:36:47 DEBUG : Backend, root: dest: List: 
2020/05/24 09:36:48 DEBUG : Backend, root: dest: design-book.pdf
2020/05/24 09:36:48 DEBUG : Backend, root: dest: newObjectWithFullPath: design-book.pdf
2020/05/24 09:36:50 DEBUG : Backend, root: dest: Features
2020/05/24 09:36:50 DEBUG : Backend, root: dest: Waiting for checks to finish
2020/05/24 09:36:50 DEBUG : design-book.pdf: Modification times differ by -16m14.697906281s: 2020-05-23 15:44:35.697906281 +0800 CST, 2020-05-23 15:28:21 +0800 CST
2020/05/24 09:36:50 DEBUG : Backend, root: dest: Waiting for transfers to finish
2020/05/24 09:36:50 DEBUG : Backend, root: dest: Features
2020/05/24 09:36:50 DEBUG : design-book.pdf: Update: design-book.pdf

First rclone list remote files, but it seems that rclone think /design-book.pdf is dest file, but not /dest/design-book.pdf, but if I add f.root to path in List, it maybe wrong in other cases.
I've read some other backend's code, but they only add f.root in Copy and DirMove, I don't know why.
Can you help me, thanks.

You should add the root in in NewFs and use it everywhere.

These are used to make absolute paths. Copy and DirMove can move to remotes with different roots so they need to be regularized first.

OK. But I need f.root(dest in this case) to update correct path, or is the above description clear?

Sorry, I haven't seen your first sentence before :sweat_smile:
I mean, I have to add root to object's path, I have to add root to object's path in List or NewObject, because when running copy, rclone will use object created by NewObject, as dest object, but I can't add it in List or NewObject, or it will worng when running ls.

I would say look at the examples in the other backends..

Are you writing a bucket based backend or a file system like backend?

The bucket based backends are all quite standardised now.

Thanks.
I'm writing a file system like backend.
I've found the solution: define 2 path in object: relative path and absolute path, only o.Remote() returns relative path, in other cases use absolute path. By the way, because like box, onedrive use ID to locate the object, so they don't have such problem, and I've read local's codes, it just add f.root to path in newObject.

Sounds reasonable, though if you can calculate absolute path from f.root and relative path then it will save memory if you millions of objects.

Yes, but I just use this method now. :grimacing:
It can keep code simple (less contact calling), and if the object is running some function, the contacted string still use memory, and maybe in most time of the object's life cycle, it runs functions that require absolute path.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.