Skip to content
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

Merged
merged 2 commits into from
May 31, 2024
Merged

Rename check files #459

merged 2 commits into from
May 31, 2024

Conversation

jelly
Copy link
Member

@jelly jelly commented May 16, 2024

No description provided.

Copy link
Member

@allisonkarlitskaya allisonkarlitskaya left a 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?

dest = sys.argv[2]
# overwrite = sys.argv[3]

if libc6.renameat2(AT_FDCWD, source.encode(), AT_FDCWD, dest.encode(), RENAME_NOREPLACE) == -1:
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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 Show resolved Hide resolved
src/files-rename.py Outdated Show resolved Hide resolved
# 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()))
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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...

Copy link
Member Author

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!

@allisonkarlitskaya
Copy link
Member

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 fsmodify channel we keep discussing...

@jelly
Copy link
Member Author

jelly commented May 23, 2024

nd such) but it's pretty much exactly what I was hoping for!

Are you happy with it?

I want to move into this direction, then also do cut and copy and paste like this but in a different Python file.

@jelly
Copy link
Member Author

jelly commented May 27, 2024

We need a fallback for when renameate2 is not supported for example on a nfs mount

As we allow renaming symlinks, file and directories just mention the
name.
@jelly
Copy link
Member Author

jelly commented May 28, 2024

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]) {
Copy link
Member

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?

Copy link
Member Author

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.

@@ -436,16 +438,18 @@ const EditPermissionsModal = ({ selected, path }) => {
);
};

const setDirectoryName = (val, setName, setNameError, setErrorMessage) => {
const setDirectoryName = (val, setName, setNameError, setErrorMessage, cwdInfo) => {
Copy link
Member

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).

Copy link
Member Author

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.

Copy link
Member

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...

Copy link
Member Author

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 }) => {
Copy link
Member

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...

Copy link
Member Author

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.
Copy link
Member

@martinpitt martinpitt left a 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.

Copy link
Member

@allisonkarlitskaya allisonkarlitskaya left a 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) => {
Copy link
Member

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?

Copy link
Member

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.

@jelly jelly merged commit 19cdfa7 into cockpit-project:main May 31, 2024
12 checks passed
@jelly jelly deleted the rename-check-files branch May 31, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants