Question

I have a block of code that executes a zip command from another class:

def zip_up_contents path name
  Zipper.new path name
end

The problem is that it zips blank copies of all the files passed to it. But when I put a binding before the zip command like so:

def zip_up_contents path name
  binding.pry
  Zipper.new path name
  binding.pry
end

it zips the files successfully. I know this by checking the resulting file's byte size from within pry on the second binding point with and without the first binding present. Without the binding, the zip archive's byte size is half what it should be, and with the binding it's the size I would expect.

The "Zipper" class simply calls the system zip with backticks. I don't think that's the problem because I've used that class without trouble in other contexts. The zip utility is Zip 3.0 on Ubuntu 10.04.

I have no idea why the presence of the binding makes a difference. If anyone has encountered anything similar, or has thoughts about how to better debug the issue, I'd appreciate hearing about it.

EDIT: For anyone encountering anything similar, I resolved this by calling fsync on the files prior to zipping them: http://www.ruby-doc.org/core-2.0.0/IO.html#method-i-fsync

Was it helpful?

Solution

I had this problem with some Rspec tests last week -- turned out to be a race condition. Is there any chance that the file hasn't been saved when you pass it to be zipped? I mean, maybe the binding.pry is just giving it a chance to catch up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top