Re: g_spawning three processes: one after another only when...




There is a problem in the set of piped command above. The last
filename (the one in bzip2) must be different from the first one
(the one in cat) otherwise I get a bzip2 unexpected file end
error.

The final redirection truncates the original file.  Which is where the magic of temporary files come into 
play.  You run your pipe, sending the output to a temporary file, and then only once everything has 
compleated SUCCESSFULLY, move the temporary file over top of the original.  This allows you to back out if 
something goes wrong part way (it's also what happens in almost every sane archive program about).

Oh, it's a good idea to make the temporary file's permissions 0600.


I need the filename be the same when deleting a file from a .tar.bz!
Is there a workaround to the "piped version" or I'm forced to
perform the three steps I cited in my first email?

If you're worried about the extra space required by the temporary archive, read the file youself, feeding it 
into the pipeline (the three commands can still be chained by pipes instead of having to fiddle it all 
manually), feeding the output back into the source file. 

You'll certainly need to keep track of the read and write positions yourself because you'll need to jump back 
and forth in the file.  You'd probably also want to at least buffer the data being read back from the 
pipeline, incase something freaky happens that causes the output stream to exceed the read pointer into the 
file.  The easiest way would probably be to do some trickery with a FIFO queue of smallish (couple KB) 
buffers (only writing complete buffers at a time would probably make for a half-way decent optimisation on 
its own).

Mind you, that idea is very very bad.  If something breaks part way though, you've probably just destroyed 
the file.


Fredderic

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]