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

Don't move a file under a directory when renaming #404

Closed
wants to merge 2 commits into from

Conversation

jelly
Copy link
Member

@jelly jelly commented Apr 25, 2024

We rename in Files by moving the file to the new filename but when this is a directory mv moves the file to that directory instead. This is quite logical in a shell but not in a GUI, there it is unexpected behaviour.

Closes: #399

@@ -206,8 +206,8 @@ const RenameItemModal = ({ path, selected }) => {
: path.join("/") + "/" + name;

cockpit.spawn(is_current_dir
? ["mv", path.join("/"), newPath]
: ["mv", path.join("/") + "/" + selected.name, newPath],
? ["mv", "-T", path.join("/"), newPath]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this should be covered. Let's try to cover that in a follow up but let's think about it:

This is about renaming the current dir, which we no longer support, so this is dead code.

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.

Looks good, thanks!

I guess we get something like "targetname: Is a directory"?

Tests would be nice ;)

@jelly
Copy link
Member Author

jelly commented Apr 26, 2024

Looks good, thanks!

I guess we get something like "targetname: Is a directory"?

We get this: https://github.com/cockpit-project/cockpit-files/pull/404/files#diff-e86755442bc7d21f0414014b3c356b54d6650e8ed9bffcc4f5858d1154df80e1R556

Tests would be nice ;)

I've added a test, see the test/check-application changes. One missing test is rename a file to an existing file. We should imo test that.

@jelly
Copy link
Member Author

jelly commented Apr 26, 2024

Added a test for this scenario which shows the wrong behavior...

> debug: process spawn: ["mv","-T","/home/admin/newfile","/home/admin/existing"]
> debug: send control: {"payload":"stream","spawn":["mv","-T","/home/admin/newfile","/home/admin/existing"],"superuser":"try","err":"message","command":"open","channel":"1:1!17","host":"localhost","flow-control":true}

This just moves newfile into an existing file without warning. Let's fix it in this PR as I already have a test.

@jelly
Copy link
Member Author

jelly commented Apr 26, 2024

Turns, out we likely want just --no-clobber, let's also not write short arguments but write them out so the code is readable.

We rename in Files by moving the file to the new filename but when this
is a directory `mv` moves the file to that directory instead. This is
quite logical in a shell but not in a GUI, there it is unexpected
behaviour.

Furthermore when renaming an existing file we replace it, that is
unexpected as well and should be possible but in the first place should
warn.

Closes: cockpit-project#399
In db968b2 we unified the sidepanel menu and the
contextmenu so they would be identical. This removed the ability to
rename the current directory, this is not something GNOME Files supports
or something we want to support.
@jelly
Copy link
Member Author

jelly commented Apr 26, 2024

This is flaky or coreutils changed behaviour. Re-trying once.

@jelly
Copy link
Member Author

jelly commented Apr 26, 2024

Yup, this is broken. Needs work.

@jelly
Copy link
Member Author

jelly commented Apr 26, 2024

[root@archlinux admin]# mv -T  newfile dest && echo 1
mv: cannot overwrite directory 'dest' with non-directory 'newfile'
[root@archlinux admin]# mv -T -n  newfile dest && echo 1
1

Yeah this is great :) It is likely a bug in coreutils as it happens in rawhide as well. Fedora 40 has 9.4 while Arch has 9.5

This is indeed the case see:

https://github.com/coreutils/coreutils/blob/master/NEWS#L123
https://github.com/coreutils/coreutils/blob/master/NEWS#L95

As alternative @allisonkarlitskaya suggested passing -i instead, hoping that this will work with cockpit.spawn and that we can pass y or n via .input() on stderr. This sounds like some nice async work!

@allisonkarlitskaya
Copy link
Member

allisonkarlitskaya commented Apr 26, 2024

As alternative @allisonkarlitskaya suggested passing -i instead, hoping that this will work with cockpit.spawn and that we can pass y or n via .input() on stderr. This sounds like some nice async work!

If you don't want to do the async work, there's a somewhat easier version:

$ cpf spawn -- mv -i -T a b stderr=message : done ch1 : wait | spy -m cockpit.bridge
...
{
  "exit-status": 1,
  "message": "mv: overwrite 'b'? ",
  "command": "close",
  "channel": "ch1"
}

with the successful case looking like

$ cpf spawn -- mv -i -T a c stderr=message : done ch1 : wait | spy -m cockpit.bridge
...
{
  "exit-status": 0,
  "message": "",
  "command": "close",
  "channel": "ch1"
}

The key here is done. If you don't send it, the channel will hang waiting for the answer. If you do send it, then mv will even give you a nice non-zero exit code.

If you do want to do the async work, that's err=out.

@jelly
Copy link
Member Author

jelly commented May 7, 2024

Le JS code:

        cockpit.spawn([
            "mv", "--interactive", "--no-target-directory",
            path.join("/") + "/" + selected.name, newPath
        ],
                      { superuser: "try" }).input()
                .then(() => Dialogs.close())
                .catch(err => {
                    setNameError(err.message);
                });

@jelly
Copy link
Member Author

jelly commented May 16, 2024

This needs to be expedited as renaming a folder into a new folder still works which is wrong.

@jelly
Copy link
Member Author

jelly commented May 22, 2024

Superseeded by #459

@jelly jelly closed this May 22, 2024
@jelly jelly deleted the move-as-expected branch May 22, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renaming a file to the name of a current directory moves it there
2 participants