Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I ask this question because I'd like to be able to unpack an archive that may also contain the very program that is calling 7zip to unpack the archive. Linux/UNIX allows a file to be deleted or renamed while it's in use, but does not allow it to be opened for writing.

share|improve this question

2 Answers 2

The answer is yes and no.

With the extract command for 7zip there should not be a temp file created. This does happen on Windows though when using Windows Explorer drag and drop (taken from documentation at http://www.7-zip.org/faq.html, ctl-f search for temp).

You are on Linux though.

To be 100% sure that this does not happen on Linux I created and then extracted a large archive and ran the program through strace:

strace -a88 -- 7z e byob.7z 2>&1

I only saw the existing files in the current working directory unlinked before overwrite and the only files accessed were files in the current working directory.

Please test for yourself to verify that I did not miss something.

I hope that this helps you.

share|improve this answer
    
I did the same thing but was unable to determine if the original filename was truncated and growing a buffer at a time or whether it was unpacked to a temp and then moved/renamed to the target. The latter seems like better programming practice - in the event the unpack fails at least it wouldn't have destroyed a perfectly good file. –  Gary Stampa Apr 15 '12 at 12:02

Your question is about executable (or script) file1, calling a mechanism that creates a new file1 (in the same place).

From what I understand about file-systems on Unix, this calls for a clobber of file1 while it is open (for execution). The way this happens is, the clobber causes original file1 to be unlinked but since it is open it does not really get removed. It however no longer occupies the name file1 in that directory. The new file1 is created in a separate location (using the correct name). When the older file1 completes execution and exits, it is deleted. You should be left with the new file1 existing though.

Caveat: This is largely guesswork based on my partial knowledge. Maybe someone here with more file-systems concepts will affirm or correct it. Meanwhile, I suggest you take this answer only as a theoretical one and not base your solutions on it without further experimental verification.

share|improve this answer
    
I was hunting throughout the 7zip docs and elsewhere trying to see if it was the practice of the program to make a temp then rename to target. Even if it does it today, it may not tomorrow if they make code changes. I'm going through the source code now. –  Gary Stampa Apr 15 '12 at 12:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.