p7zip-project / p7zip

A new p7zip fork with additional codecs and improvements (forked from https://sourceforge.net/projects/sevenzip/ AND https://sourceforge.net/projects/p7zip/).
805 stars 111 forks source link

7za extracting symlinks as text files on some filesystem #164

Open mboisson opened 3 years ago

mboisson commented 3 years ago

Hi, I have a .7z file which contains symbolic links. If I extract it on a xfs filesystem, it extracts symlinks correctly. If I extract it on a CephFS filesystem, it saves symlinks as text files which contain the path to their targets, i.e.

cat /home/mboisson/STAR-CCM+16.06.008/hdf5/1.10.5-cda-004/linux-x86_64-2.12/gnu7.1/libhdf5_hl_cpp.so.100
libhdf5_hl_cpp.so.100.1.3

CephFS does support symbolic links, so I'm not sure why 7za is not doing the right thing.

mboisson commented 3 years ago

Here is a small test on CephFS:

rm -rf testdir unpack; mkdir testdir; cd testdir; touch b; ln -s b a; cd ..; ls -rl testdir; 7za a testdir.7z testdir; 7za x -y -ounpack testdir.7z; ls -l unpack/testdir/; cat unpack/testdir/a

total 1
-rw-rw-r-- 1 mboisson mboisson 0 18 nov 19:09 b
lrwxrwxrwx 1 mboisson mboisson 1 18 nov 19:09 a -> b

7-Zip (a) [64] 17.04 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs x64)

Open archive: testdir.7z
--
Path = testdir.7z
Type = 7z
Physical Size = 174
Headers Size = 169
Method = LZMA2:12
Solid = -
Blocks = 1

Scanning the drive:
1 folder, 2 files, 1 bytes (1 KiB)

Updating archive: testdir.7z

Items to compress: 3

Files read from disk: 1
Archive size: 174 bytes (1 KiB)
Everything is Ok

7-Zip (a) [64] 17.04 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs x64)

Scanning the drive for archives:
1 file, 174 bytes (1 KiB)

Extracting archive: testdir.7z
--
Path = testdir.7z
Type = 7z
Physical Size = 174
Headers Size = 169
Method = LZMA2:12
Solid = -
Blocks = 1

ERROR: E_FAIL

Archives with Errors: 1

total 1
-rw-rw-r-- 1 mboisson mboisson 1 18 nov 19:09 a
-rw-rw-r-- 1 mboisson mboisson 0 18 nov 19:09 b
b

And the same on a xfs:

rm -rf testdir unpack; mkdir testdir; cd testdir; touch b; ln -s b a; cd ..; ls -rl testdir; 7za a testdir.7z testdir; 7za x -y -ounpack testdir.7z; ls -l unpack/testdir/; cat unpack/testdir/a
total 0
-rw-rw-r-- 1 mboisson mboisson 0 18 nov 19:11 b
lrwxrwxrwx 1 mboisson mboisson 1 18 nov 19:11 a -> b

7-Zip (a) [64] 17.04 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs x64)

Scanning the drive:
1 folder, 2 files, 1 bytes (1 KiB)

Creating archive: testdir.7z

Items to compress: 3

Files read from disk: 1
Archive size: 175 bytes (1 KiB)
Everything is Ok

7-Zip (a) [64] 17.04 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs x64)

Scanning the drive for archives:
1 file, 175 bytes (1 KiB)

Extracting archive: testdir.7z
--
Path = testdir.7z
Type = 7z
Physical Size = 175
Headers Size = 170
Method = LZMA2:12
Solid = -
Blocks = 1

Everything is Ok

Folders: 1
Files: 2
Size:       1
Compressed: 175
total 0
lrwxrwxrwx 1 mboisson mboisson 1 18 nov 19:11 a -> b
-rw-rw-r-- 1 mboisson mboisson 0 18 nov 19:11 b
mboisson commented 3 years ago

I debugged p7zip, and it turns out that the issue is that lstat yields a value of 0 for st_dev. This causes this test to fail and return without transforming the files into symlinks.

https://github.com/jinfeihan57/p7zip/blob/master/CPP/Windows/FileDir.cpp#L862

Why is _dev == 0 an abort condition for converting files into symlinks ?

If I comment this test, then the extraction works just fine.

mboisson commented 3 years ago

I applied this patch to our local build, but I would like to know what unforeseen consequence this may have

https://github.com/ComputeCanada/easybuild-easyconfigs/blob/087dac6111dd08e5d85a310467dcd551b8ac7d35/easybuild/easyconfigs/p/p7zip/p7zip-17.04-CephFS.patch