`mv` does not work as expected on private trees
Problem
When using mv on the private side, it creates the full to path at root of the private tree that it is operating on. (sorry this is very confusing to describe in words :sweat_smile:)
To illustrate
- You have access to the private fs at
private/Apps/fission/test-app(and that is you entry point into the private FS) - and you have a file at
private/Apps/fission/test-app/file.txt - you call
mv('private/Apps/fission/test-app/file.txt', 'private/Apps/fission/test-app/nested/file.txt') - Expected: you now have the same file at
private/Apps/fission/test-app/nested/file.txt - What happens: you now have the same file at
private/Apps/fission/test-app/Apps/fission/test-app/nested/file.txt:scream:
Impact
Creates unexpected directory structures when using mv
Solution
This is because in filesystem.runOnNode, we strip the prefix before the entry point (private/Apps/fission/test-app in this case) before performing operations.
But we don't strip the prefix off of to.
This will take some extra work to move between different private subtrees. We can throw an error on that for now (similar to how we error when trying to move between public/private).
For now, we can just compare from & to and strip the same prefix off of to before passing on to the PrivateTree
Is there a workaround for moving files without this issue, can I do relative paths? Or can someone guide me to fix this?
Okay I was being dumb, there is an easy work around.. copy + delete = move
await fs.mv(fromPath, toPath)
await fs.publish()
is the same as
await fs.write(toPath, await fs.read(fromPath))
await fs.rm(fromPath)
await fs.publish()