-
Notifications
You must be signed in to change notification settings - Fork 37
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
Rename check files #459
Rename check files #459
Conversation
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.
This is currently a bit rough around the edge (commented out code and such) but it's pretty much exactly what I was hoping for!
Are you happy with it?
src/files-rename.py
Outdated
dest = sys.argv[2] | ||
# overwrite = sys.argv[3] | ||
|
||
if libc6.renameat2(AT_FDCWD, source.encode(), AT_FDCWD, dest.encode(), RENAME_NOREPLACE) == -1: |
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.
encode()
isn't quite right here. To match what Python normally does with filesystem encoding (which is what the bridge does with the filenames in fsinfo) you need to use surrogate escapes.
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.
It's actually kinda funny since the string we have in sys.argv
was actually decoded from the commandline (after being encoded for it, from a string, by the bridge).
In all of those cases, though, I think errors='surrogateescape'
is what's in play.
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.
Thanks! I kinda wish we could spawn with native types auto converted like dbus but eh :-) (dream on, dreaaam on)
src/files-rename.py
Outdated
# overwrite = sys.argv[3] | ||
|
||
if libc6.renameat2(AT_FDCWD, source.encode(), AT_FDCWD, dest.encode(), RENAME_NOREPLACE) == -1: | ||
sys.stderr.write(os.strerror(ctypes.get_errno())) |
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.
I feel like I'd like to see some sort of structured json output similar to the thing that fsinfo reports on errors...
At the least, though: we should have some way of uniquely identifying the EEXIST case, no?
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.
I was considering returning a different exit code, json feels a bit too overengineered. There are only two scenario's:
- All Good = 0
- General error = 1
- File exists = 2
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.
I keep thinking that I Want to implement some kind of a strerror mechanism in javascript...
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.
I agree, not sure how I get errno.EEXISTS converted to str(). I feel this warrants a bigger discussion and some more thinking outside this PR. I do like the idea!
btw: I feel like this could become a template for more such operations, and once we collect the lot of them it could form the basis of the |
I want to move into this direction, then also do |
We need a fallback for when |
As we allow renaming symlinks, file and directories just mention the name.
I dropped renameat2 as obviously folks are going to want to rename files in a NFS share or something else, which renameat2 does not support. So we would need a fallback there. |
} else if (val.includes("/")) { | ||
setNameError(_("Directory name cannot include a /.")); | ||
setNameError(_("Name cannot include a /.")); | ||
} else if (cwdInfo?.entries[val]) { |
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.
So no "Rename and overwrite" option, at present?
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.
Not presently, I have supported it in renameat2
but not here as this was a completely new scenario and when I made UI for it I did not receive positive feedback.
src/fileActions.jsx
Outdated
@@ -436,16 +438,18 @@ const EditPermissionsModal = ({ selected, path }) => { | |||
); | |||
}; | |||
|
|||
const setDirectoryName = (val, setName, setNameError, setErrorMessage) => { | |||
const setDirectoryName = (val, setName, setNameError, setErrorMessage, cwdInfo) => { |
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.
This function should be renamed now.
Note also, the mkdir PR stops using this function (since it creates its own copy in a separate file).
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.
I'd say we refactor it there then.
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.
I mean, this function has always had the wrong name (since it was used from the rename dialog as well) but you've fixed the messages here, but not the function name...
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.
Changed it, but imo it is out of scope for this review
@@ -185,6 +186,7 @@ const CreateDirectoryModal = ({ currentPath }) => { | |||
|
|||
const RenameItemModal = ({ path, selected }) => { |
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.
I wonder if you'd like to move this to a new tsx
file in src/dialogs/
like the mkdir
PR does...
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.
No, this PR has been open for 2 weeks now, and then it will conflict again.
This slightly improves the situation where one can rename an existing file but there is still an obvious race. The validation only happens when one changes the input, if you touch something via for example an ssh session you will still overwrite the file. For that we can't use `--no-clobber` as that does not fail with an informative error.
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.
Thanks! I like this. It's a gradual improvement, simple, and robust. Not landing myself yet, as there was lots of discussion with @allisonkarlitskaya and she may want the last word here.
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.
This is pretty trivial now, and it's a step in the right direction.
Strictly speaking, the suggested change would be nice, but it's no big deal if we want to handle that later.
@@ -436,7 +438,7 @@ const EditPermissionsModal = ({ selected, path }) => { | |||
); | |||
}; | |||
|
|||
const setDirectoryName = (val, setName, setNameError, setErrorMessage) => { | |||
const setInputName = (val, setName, setNameError, setErrorMessage, cwdInfo) => { |
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.
minor nag: this change landed in the wrong commit. The chosen name is also a bit weird, so if you're gonna move it to the other commit (which makes all the other changes to this function) maybe call it something like setFileName()
instead?
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.
And it's a completely separate topic, but I dislike the structure of this function: I reworked it for my mkdir patch to be a simple function which took the proposed filename and returned a string describing an error (in case of error) or undefined for "no error". I kept the state-modification logic in the component itself, which reduced the number of arguments to the error-checking function.
No description provided.