8000 Calling the ZipFileGenerator.write function to create a zip file creates a lock on the files, if the files are used further in the process . The file isn't closed. · Issue #307 · rubyzip/rubyzip · GitHub
[go: up one dir, main page]

Skip to content
< 8000 /div>

Calling the ZipFileGenerator.write function to create a zip file creates a lock on the files, if the files are used further in the process . The file isn't closed. #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ZaidMomin1 opened this issue Nov 25, 2016 · 2 comments

Comments

@ZaidMomin1
Copy link
ZaidMomin1 commented Nov 25, 2016

Scenario:
I have a function that downloads the zipped code from aws s3-bucket. Extracts the zip file in a temp folder and then modifies few files from the extracted zip file and create a zip after modification. Later when I try to delete the temp folder it throws me "The process cannot access the file because it is being used by another process."
(NOTE: everything takes place in the same process meaning in the same function).
After carefully looking the code found in the below code
def writeEntries(entries, path, io)

entries.each { |e|
  zipFilePath = path == "" ? e : File.join(path, e)
  diskFilePath = File.join(@inputDir, zipFilePath)
  puts "Deflating " + diskFilePath
  if  File.directory?(diskFilePath)
    io.mkdir(zipFilePath)
    subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
    writeEntries(subdir, zipFilePath, io)
  else
    io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
  end
}

end
In line io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}, the file is opened but not closed.

Solution :
So I modified the above line of code as follows:

disk_file = File.open(diskFilePath, "rb")
io.get_output_stream(zipFilePath) { |f|
f.puts(disk_file.read())
}
disk_file.close

and was successfully able to delete the temp folder.
Would be great if the modification can be included in the file.

Thanks,
Zaid

@ddutchie
Copy link

Glorious.

@jdleesmiller
Copy link
Member
jdleesmiller commented May 24, 2019

Thanks for reporting this. It looks like the example_recursive.rb sample has since been updated and no longer has this problem.

Edit: specifically, it was fixed in #297.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0