If you're rewriting this section now would be a great time to use better variable names than 'cpack' and 'trailer' - what are those anyway?
Also, maybe 'local_dir' instead of 'ldir' - readability is really important, at least to me, and disk space is cheap.