Menu

#2540 7z defaults to archiving files in current directory

open
nobody
None
5
2025-01-03
2024-12-30
yokota
No

7zip uses current directory if I uses "a" (add) command with no file names specified.

# add command without file names
7z a foo.7z

...(add files in current folder to foo.7z)

I think this is an unwanted behavior.
Because other archiver like Zip and Tar provides error when no file names specified.

# provides errors and not touch archive file
zip foo.zip
tar cf foo.tar

"rn" (rename) command acts more strange.
When I don't add file names for "rn" command, 7zip acts like "a" (add) command and adds files in current directory.

# rename command with no file rename list
7z rn foo.7z

...(add files in current folder to foo.7z)

I think these 7zip behavior is not expected for users.
Because other archiver like Zip and others doesn't add files when not specified any files.

See Debian's bug report for more info:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1091693

Discussion

  • Igor Pavlov

    Igor Pavlov - 2024-12-30

    I'll fix the issue with rename command.

    But I don't want to change action for such command:

    7z a foo.7z
    

    It's possible that some users suppose that it must work that way as it works now. If we change it now, the some working scripts will not work for them anymore.
    The idea was that if we call simple command:

    7z a foo.7z
    7z x foo.7z
    

    7-zip processes all files for these commands:

    7z a foo.7z *
    7z x foo.7z *
    

    So no_file_mask works same was as * universal mask.
    If we change the behavior for a command, then there will be difference between a and x commands .

     
    • yokota

      yokota - 2025-01-03

      I was added notes about this issues to usage text on Debian package.
      I also attach a patch file for this fix.

       
  • Contextual Subtext

    Can you at least modify the behavior of "7z a foo.7z" so that 7z doesn't automatically add the archive to itself?

    Here's the behavior of dar, which also defaults to automatic archiving of the current directory:

    $ dar -c archive
    WARNING! The archive is located in the directory to backup, this may create an endless loop when the archive will try to save itself. You can either add -X "archive.*.dar" on the command line, or change the location of the archive (see -h for help). Do you really want to continue? [return = YES | Esc = NO]

    Also, "7z d foo.7z" (without any file selector) defaults to deleting everything in "foo.7z". This is bad when user accidentally presses enter without typing file selector.

    Maybe you can add a -f(orce) switch for dangerous actions, such as delete everything or when the archive tries to save itself?.

     
  • oset jan

    oset jan - 2025-01-03

    You're not the only one who thinks this policy is overboard.
    I got caught in a loop of creating increasingly larger archives when forgot to enter file list or had some error in script that passed empty file list.
    I would rather to get an error than to compress everything as it is.
    Considering that there are multiple, other ways (below) to pass all current directory as file list I would welcome the end of this policy.

    7z a foo.7z .
    7z a foo.7z *
    7z a foo.7z "*"
    
     

Log in to post a comment.

MongoDB Logo MongoDB