-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using rename to move an existing file to a subdirectory #442
base: master
Are you sure you want to change the base?
Conversation
This currently has the same problems as #400 and #305
Then nvim . and edit the buffer to look like this:
When you save, it moves a.txt to foo/a.txt, obliterating the pre-existing file. The reason this feature does not exist yet is because of the difficulty in ensuring that these operations are safe and cannot produce unexpected data loss. |
Great points @stevearc, I've pushed a couple ideas to resolve this. Added a Below are the use cases I've identified, let me know if I'm missing any. If you're happy with the approach I'll add some tests to tie it up.
3a. bar/bar.txt is below bar/
Previous Behaviour: 3b. bar/bar.txt is above bar/
Previous Behaviour: New Behaviour: |
@stevearc what do you think this solution? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the right general idea of checking for conflicts before performing the actions. Two issues with the current approach:
- It's not supported in the ssh adapter. It would be ideal if all the adapter special-case logic could be removed, but that may not be possible because the trash adapters may still need to be handled differently. Haven't thought about that too deeply yet.
- It checks for collisions with the current state of the filesystem, but not the target state. For example: if you put a file into
foo/bar/baz.txt
from multiple locations in the same operation, we won't catch that and they'll clobber each other with only one winning. Likewise, if you put a file intofoo/bar.txt
(with a conflicting existing file) and rename the current file tofoo/baz.txt
in the same operation, it will incorrectly block you.
To be a truly safe operation, each of these nested files will need to be checked to see if there are any conflicts in any open oil buffers, as well as the target directory. Note that the current implementation seems to support ../foo.txt
, which can get complicated. For example, in /home/user
you can move a file to ../../foo.txt
and ../../../foo.txt
, which look different but both resolve to /foo.txt
I suspect that pursuing the above goal will also solve the issue with the unsupported ssh adapter, since the approach won't be using a direct "does this file exist" check.
@timtatt's solution looks fine to me, but if I may I'd like to add my two cents to this statement:
Since Neovim users are mostly software developers, I personally think we can trust they know what they're doing (well, most of the time 😊) and let them deal with the consequences. To me the "move by renaming" operation wouldn't be much different than opening a terminal and executing: mv foo.txt bar/foo.txt I'd say this But still I understand why accidental data loss is a valid concern, so suppose Oil were to allow silent overwriting files by move-renaming them, this behavior could be disabled by default and Oil could provide some configuration option to explicitly enable it. Assuming @timtatt's solution eventually gets implemented, there could be an additional option to enable explicitly overwriting a file via some kind of syntactic element, e.g. when changing
to
you could add something like
Just thinking out loud. |
Previously an oil window with
changing to:
would result in the following error "Filename cannot contain path separator"
With this code change, running the above Oil change will create a subdirectory
bar
if it doesn't exist and will movefoo.txt
inside