rbauction / missing-link

Automatically exported from code.google.com/p/missing-link
0 stars 0 forks source link

HTTP GET to outFile in non-existent directory doesn't create parent directories #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If I do a HTTP GET to an outFile in a directory that doesn't exist yet, I would 
expect ML to attempt the creation of the parent directories, only failing the 
HTTP GET if that creation is unsuccessful.

Original issue reported on code.google.com by stephens...@googlemail.com on 16 Aug 2011 at 2:46

GoogleCodeExporter commented 9 years ago
Added patch for submission

Original comment by stephens...@googlemail.com on 16 Aug 2011 at 4:38

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by alex.she...@gmail.com on 18 Aug 2011 at 1:16

GoogleCodeExporter commented 9 years ago

Original comment by alex.she...@gmail.com on 18 Aug 2011 at 2:14

GoogleCodeExporter commented 9 years ago
Fixed so when writing entity to an outFile, parent directories are 
automatically created.

Bulk of code was from a user submitted patch 
http://code.google.com/p/missing-link/issues/detail?id=23#c1

Changed will be available in 1.1.3

Original comment by alex.she...@gmail.com on 18 Aug 2011 at 2:26

GoogleCodeExporter commented 9 years ago

Original comment by alex.she...@gmail.com on 19 Aug 2011 at 12:51

GoogleCodeExporter commented 9 years ago
We need to re-open this issue please, I've discovered a concurrency issue with 
my original patch.

  protected static void mkdirs(final File file) {
    final File dir = file.getParentFile();
    if (!dir.exists()) {
      final boolean mkdirs = dir.mkdirs();
      if (!mkdirs) {
        throw new BuildException("Could not make directories for " + dir.getAbsolutePath());
      }
    }
  }

If thread B enters this method after thread A has evaluated dir#exists as false 
*but before* thread A has finished dir#mkdirs, thread B may call dir#mkdirs and 
receive false - which results in a BuildException. 

Original comment by stephens...@googlemail.com on 13 Sep 2011 at 4:01

GoogleCodeExporter commented 9 years ago
We could log an INFO or a WARNING that the parent directory could not be 
created, but I'm wary of logging something that low level. It could be 
misleading. I think we're better off with an explicit check for permissions 
problems, and simply ignoring the return value from File#mkdirs.

Original comment by stephens...@googlemail.com on 13 Sep 2011 at 4:18

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
A far simpler patch, where we simply call File#mkdirs regardless - if the 
directory already exists, we simply move on

Original comment by stephens...@googlemail.com on 14 Sep 2011 at 9:25

Attachments: