[comp.unix.questions] Changing .zoo archive to .lzh archive: help!

dave@cs.arizona.edu (Dave P. Schaumann) (02/17/91)

I am trying to write a script that will allow me to convert zoo archives
to lharc archives under Unix.  Here's what I have so far:

mkdir xxx
cd xxx
zoo xq// ../$1.zoo
lharc aq ../$1.lzh * `no-dot .*`
cd ..
rm -r xxx

Where "no-dot" is a simple program that echos back everything in argv[] that
isn't "." or ".."

This works fine, except for two problems: first, there might already be a
file called "xxx" in the current directory, and second, I can't have more
than one invocation going at once.

Now, I could write a program to generate a temporary directory name using
getpid() and some unlikely template, like "xx-######-temp".  What I need to
know is:

  1.  Is it a reasonable assumption that no two concurrent getpid()'s will
      return the same value?

  2.  Is there a better way to do this?

Thanks in advance for all replies.

-- 
Dave Schaumann      | DANGER: Access holes may tear easily.  Use of the access
		    | holes for lifting or carrying may result in damage to the
dave@cs.arizona.edu | carton and subsequent injury to the user.

mike (02/17/91)

In an article, cs.arizona.edu!dave (Dave P. Schaumann) writes:
>
>I am trying to write a script that will allow me to convert zoo archives
>to lharc archives under Unix.  Here's what I have so far:
>
>mkdir xxx
>cd xxx
>zoo xq// ../$1.zoo
>lharc aq ../$1.lzh * `no-dot .*`
>cd ..
>rm -r xxx
>
>Where "no-dot" is a simple program that echos back everything in argv[] that
>isn't "." or ".."

Actually, you can use ``find'' for this purpose ...

	lharc aq ../$lzh `find . \( ! -name "." -a ! -name ".." \) -print`

So, how about this snippet ...?

--- snip --- snip --- snip --- snip --- snip --- snip --- snip --- snip ---

dir=.dir$$
mkdir $dir || exit
for archive in $*; do
   cd $dir
   zoo xq// ../${archive}.zoo
   lharc aq ../${archive}.lzh `find . \( ! -name "." -a ! -name ".." \) -print`
   cd ..
   rm -fr $dir
   mkdir $dir || exit
done
rm -fr $dir

--- snip --- snip --- snip --- snip --- snip --- snip --- snip --- snip ---

>Now, I could write a program to generate a temporary directory name using
>getpid() and some unlikely template, like "xx-######-temp".  What I need to
>know is:
>
>  1.  Is it a reasonable assumption that no two concurrent getpid()'s will
>      return the same value?

It is _very_ reasonable to assume this.  Updates to the kernel proc table 
are atomic, insuring that no two "concurrent" processes have the same PID.

Hope this helps.
Cheers,
-- 
Michael Stefanik, MGI Inc., Los Angeles| Opinions stated are not even my own.
Title of the week: Systems Engineer    | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
Remember folks: If you can't flame MS-DOS, then what _can_ you flame?

mju@mudos.ann-arbor.mi.us (Marc Unangst) (02/18/91)

In article <885@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave P. Schaumann) writes:
>Where "no-dot" is a simple program that echos back everything in argv[] that
>isn't "." or ".."

Why bother?  Why not just use ".??*", and save the overhead of writing
and executing another program?

>getpid() and some unlikely template, like "xx-######-temp".  What I need to

Again, why bother?  The shell already provides access to your PID in the
form of the "$" variable.  So, you can just do this:

temp=$$xx.temp
# ...
mkdir $temp
# ...

>  1.  Is it a reasonable assumption that no two concurrent getpid()'s will
>      return the same value?

Yes; a process ID is just that -- a unique identifier assigned to an
individual process.  Since a great many things would break if two
concurrently executing processes could have the same PID, Unix kernel
writers go to great lengths to make sure updates to the process table
are atomic.

>  2.  Is there a better way to do this?

See above.

-- 
Marc Unangst                | "I think I have a bad disk.  Even though I
mju@mudos.ann-arbor.mi.us   |  folded it to fit into my drive, it still
...!umich!leebai!mudos!mju  |  doesn't work..." -Caller to a tech support line