4

system("tar -czf #{RAILS_ROOT}/tmp/export-result #{RAILS_ROOT}/tmp/export")

When I decompress the resulting file I get

app/c3ec2057-7d3a-40d9-9a9d-d5c3fe3ffd6f/home/tmp/export/and_the_files

I would like to just get:

export_result/and_the_files

How do I change my TAR call to accomplish this?

solution:

system("tar -czf #{RAILS_ROOT}/tmp/export.tgz --directory=#{RAILS_ROOT}/tmp export/")

3

This is how you do it,

tar cfz target.tgz --directory=TARGET_DIR subdir_list

In your case it would look like,

tar cfz target.tgz --directory=app/c3ec2057-7d3a-40d9-9a9d-d5c3fe3ffd6f/home/tmp export/
  • So, first I specify where I want to save the result 'target.tgz' then I specify where the contents are and what subdirs should be removed. Correct? – Nerian Feb 19 '11 at 13:28
  • This is an app hosted at Heroku, so the only place where I can write is RAILS_ROOT/tmp/ how do I write it so that target.tgz end up there? – Nerian Feb 19 '11 at 13:31
  • I did it: system("tar -czf #{RAILS_ROOT}/tmp/export.tgz --directory=#{RAILS_ROOT}/tmp export/") – Nerian Feb 19 '11 at 13:43
  • right! Good for you :-) – nik Feb 19 '11 at 18:27
1

Change to #{RAILS_ROOT} before compression and don't specify it in the source files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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