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

ArchiveWrite.add_files() chokes on broken symlinks #46

Closed
superr opened this issue Dec 3, 2016 · 3 comments
Closed

ArchiveWrite.add_files() chokes on broken symlinks #46

superr opened this issue Dec 3, 2016 · 3 comments
Labels

Comments

@superr
Copy link
Contributor

superr commented Dec 3, 2016

Hello,

First, thanks for this wonderful project :)

I am trying to create a gzipped cpio_newc archive (Android ramdisk). The contents contain some root owned files so I am using sudo python3 to open the interpreter. The contents also include broken symlinks which need to remain intact as they are not broken once Android boots.

I am probably doing something wrong, but when I run the below command I get errors on the broken symlinks. It seems they are being followed but the destination does not exist.

Is there a way to say something like "follow_symlinks = False" so the broken symlinks are compressed with the archive but not followed?

Thanks for your time,
SuperR

sudo python3
[sudo] password for superr: 
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import libarchive
>>> with libarchive.file_writer("ramdisk.gz", "cpio_newc", "gzip") as archive:
...     archive.add_files("ramdisk/")
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/superr/.local/lib/python3.5/site-packages/libarchive/write.py", line 64, in add_files
    with open(entry_sourcepath(entry_p), 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: b'ramdisk/sdcard'
@superr superr changed the title cpio_newc cpio_newc and broken symlinks Dec 3, 2016
@Changaco
Copy link
Owner

Changaco commented Dec 3, 2016

Hello,

No, we don't have an option for this. We probably shouldn't try to read the contents of symlinks at all, so I'd say this issue is more a bug than a missing feature.

Basically we should skip the call to the open() function you see in the traceback if entry.issym is True, and maybe for other types of entry as well.

Can you send us a pull request or do you need someone else to do it?

@Changaco Changaco changed the title cpio_newc and broken symlinks ArchiveWrite.add_files() chokes on broken symlinks Dec 3, 2016
@Changaco Changaco added the bug label Dec 3, 2016
@Changaco
Copy link
Owner

Changaco commented Dec 3, 2016

I knew we'd talked about this before. In #8 (comment) @pombredanne said:

Opening a FIFO or character/device file like this usually has funny consequences such has a hanging.

@superr
Copy link
Contributor Author

superr commented Dec 3, 2016

Pull request complete. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants