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

Analyze the renaming order of bulk-renamed files to avoid conflicts #1766

Closed
2 of 3 tasks
AminurAlam opened this issue Oct 11, 2024 · 4 comments · Fixed by #1801
Closed
2 of 3 tasks

Analyze the renaming order of bulk-renamed files to avoid conflicts #1766

AminurAlam opened this issue Oct 11, 2024 · 4 comments · Fixed by #1801
Labels
feature New feature request good first issue Good for newcomers

Comments

@AminurAlam
Copy link

yazi --debug output

Yazi
    Version: 0.3.3 (termux 2024-09-05)
    Debug  : false
    OS     : android-aarch64 (unix)

Ya
    Version: 0.3.3 (termux 2024-09-05)

Emulator
    Emulator.via_env: ("xterm-256color", "")
    Emulator.via_csi: Ok(Unknown([]))
    Emulator.detect : Unknown([])

Adapter
    Adapter.matches: X11

Desktop
    XDG_SESSION_TYPE           : None
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some(":1")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL              : Some("/data/data/com.termux/files/usr/bin/fish")
    EDITOR             : Some("/data/data/com.termux/files/usr/bin/nvim")
    VISUAL             : Some("/data/data/com.termux/files/usr/bin/nvim")
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block  : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : tmux 3.5a
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file             : 5.45
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: No such file or directory (os error 2)
    magick           : No such file or directory (os error 2)
    fzf              : 0.55
    fd               : 10.2.0
    rg               : 14.1.1
    chafa            : No such file or directory (os error 2)
    zoxide           : 0.9.6
    7z               : 17.05
    7zz              : No such file or directory (os error 2)
    jq               : 1.7.1


--------------------------------------------------
When reporting a bug, please also upload the `yazi.log` log file - only upload the most recent content by time.
You can find it in the "/data/data/com.termux/files/home/.local/state/yazi" directory.

Please describe the problem you're trying to solve

when trying to bulk rename files yazi skips renaming if desnination file already exists, even if you were going to rename the destinatoin too

this does not work as expected even though there is no conflict:

a -> b
b -> c

this makes doing something like incrementing numbers in files in bulk harder to do

01 -> 02 ×
02 -> 03 ×
03 -> 04 ×
04 -> 05 ×
05 -> 06 ×
06 -> 07 ×
07 -> 08 ×
08 -> 09 ×
09 -> 10 ✓

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

use temp/intermediate files if destination exists and is scheduled to be renamed:

a -> b.XXXXX
b -> c
b.XXXXX -> b

or reshuffle rename execution:

b -> c
a -> b

(i recommend using temp files since it also takes care of swapping files)

Additional context

No response

Validations

  • I have searched the existing issues/discussions
  • The latest nightly build of Yazi doesn't already have this feature
@AminurAlam AminurAlam added the feature New feature request label Oct 11, 2024
@sxyazi
Copy link
Owner

sxyazi commented Oct 12, 2024

I don't think using temporary filenames is a good idea because it breaks the atomic operation a -> b into two steps: a -> a.tmp and a.tmp -> b.

Since the filesystem doesn't have the concept of transactions, all I/O operations are prone to failure. This could introduce unexpected security risks, as either of these two steps could fail.

I believe a better approach would be to come up with an algorithm that automatically analyzes the order in which files should be renamed. For example, in the case of:

1:  a -> b
2:  b -> c

The renaming operations should be done in the order:

2:  b -> c
1:  a -> b

Anyone want to give it a try? All the code for bulk renaming can be found in
https://github.com/sxyazi/yazi/blob/main/yazi-core/src/manager/commands/bulk_rename.rs

@sxyazi sxyazi added the good first issue Good for newcomers label Oct 12, 2024
@sxyazi sxyazi changed the title use temporary files when bulk renaming Analyze the renaming order of bulk-renamed files to avoid conflicts Oct 12, 2024
@yw1ee
Copy link
Contributor

yw1ee commented Oct 15, 2024

Hi, I am an open source beginner looking for a good issue to contribute to for the first time. Can I try to handle this issue?

As you mentioned above, I think this problem can be solved by determining the order of rename using topological sort.

@sxyazi
Copy link
Owner

sxyazi commented Oct 15, 2024

Sure, go for it!

If you need any guidance, just let me know @yw1ee!

Copy link

I'm going to lock this issue because it has been closed for 30 days. ⏳
This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please file a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants