Files
galaxy/lib
mvdbeek 1a43ef5b83 Work around (temporarily) wrong getsize() output
I'm not sure how/why this happens, but this can be reproduced by copying a file to a location in one process, while checking the size in another process:

Run this to copy a file indefinitely:

```
import os
import shutil

open('test').write("foo")
while True:
    shutil.copy('test', 'test.file')
    os.remove('test.file')
```

In the same directory run this

```
import os

count = 0
wrong_size = False
while True:
    try:
        size = os.path.getsize('test.file')
        if size == 0:
            wrong_size = True
            wrong_count = count
        elif wrong_size and os.path.getsize('test.file') != 0:
            # We have seen the wrong size being reported, but now it's correct again
            print("Got wrong file size at %dnd try, was fixed in %dnd try" % (wrong_count, count))
            break
    except Exception:
        pass
    count += 1
```

It'll (probably) fail like this:

```
Got wrong file size at 0nd try, was fixed in 1nd try
```
or more often:
```
Got wrong file size at 31nd try, was fixed in 32nd try
```

This seems to be fixed when running os.path.getsize() another time,
so we simply do that here.
2018-01-19 08:23:50 +01:00
..