Ticket #4559 (closed defect: fixed)

Opened 2 months ago

Last modified 7 weeks ago

Bug with nested dirs in u7z mkdir action

Reported by: ponko Owned by: andrew_b
Priority: major Milestone: 4.8.32
Component: mc-vfs Version: master
Keywords: Cc:
Blocked By: Blocking:
Branch state: merged Votes for changeset: committed-master

Description

Current

$P7ZIP a -w"$dir" "$1" "$dir"/"$2" ..

Should be

$P7ZIP a "$1" "$dir/${2%%/*}" ..

Case1

  • open some 7z archive
  • press F7
  • type a/b/c, press enter
  • restart mc
  • open the archive
  • expected: "a", "a/b", "a/b/c" dirs
  • actual: "c" dir

Case2

  • left panel: open some 7z archive
  • right panel: create x/y/z path, copy x to the left
  • restart mc
  • open the archive
  • expected: "x", "x/y", "x/y/z" dirs
  • actual: "x", "y", "z" dirs

I could guess what one meant putting -w there, and it was completely wrong idea. -w option:

Sets the working directory for the temporary base archive. By default, 7-Zip builds a new base archive file in the same directory as the old base archive file. By specifying this switch, you can set the working directory where the temporary base archive file will be built. After the temporary base archive file is built, it is copied over the original archive; then, the temporary file is deleted.

By default, 7z only looks at the last part of the path. E.g. if we say "7z a 1.7z a/b/c", it adds the "c" dir. There is the "-spf" option (idk since which version) to make it use the whole path provided, but it means more code in our case:

cd "$dir"
$P7ZIP a -spf "$1" "$2" ..
cd -

The one-liner $P7ZIP a "$1" "$dir/${2%%/*}" .. looks better.

Change History

comment:1 Changed 7 weeks ago by andrew_b

  • Owner set to andrew_b
  • Status changed from new to accepted
  • Votes for changeset set to andrew_b
  • Branch state changed from no branch to on review
  • Milestone changed from Future Releases to 4.8.32
Last edited 7 weeks ago by andrew_b (previous) (diff)

comment:2 Changed 7 weeks ago by ponko

Andrew, I need to clarify something in the comment text. The "by default, 7z only looks at the last part of the path" is only true for ABSOLUTE pathes. u7z operates on absolute pathes and my patch works, but the commit text should be changed:

this

If we need to create dir "z" in an archive under path "x/y/", such command
works: `mkdir -p x/y/z && 7z a some.7z x`. If the disposable subdirs should be
created not in the current dir, but under some $temp dir, it would be `mkdir -p
$temp/x/y/z && 7z a some.7z $temp/x`.

should be replaced with

When adding something to a 7z archive by its absolute path, 7zip only uses the
last part of the path by default. E.g. `7z a 1.7z /tmp/a/b/date.txt` would add
date.txt to the root dir inside the archive. If we wanted the file to be under
`a/b/` inside the archive as well, it should be `7z a 1.7z /tmp/a`.

comment:3 Changed 7 weeks ago by ponko

Also, in the post text above my description of the -spf option is wrong. The option is only related to ABSOLUTE pathes again:

  • 7z a 1.7z /tmp/a/b/date.txt would add date.txt to the root dir inside the archive
  • 7z a -spf 1.7z /tmp/a/b/date.txt would add date.txt to the archive as /tmp/a/b/date.txt

Relative pathes are added as a whole, no matter if there is -spf or not.

comment:4 Changed 7 weeks ago by andrew_b

Fixed commit message. Pushed forced.

comment:5 Changed 7 weeks ago by zaytsev

  • Votes for changeset changed from andrew_b to andrew_b zaytsev
  • Branch state changed from on review to approved

I didn't test, but code and description look sound.

comment:6 Changed 7 weeks ago by andrew_b

  • Status changed from accepted to testing
  • Votes for changeset changed from andrew_b zaytsev to committed-master
  • Resolution set to fixed
  • Branch state changed from approved to merged

comment:7 Changed 7 weeks ago by andrew_b

  • Status changed from testing to closed
Note: See TracTickets for help on using tickets.