Skip to content

Commit 62f86de

Browse files
authored
Merge pull request #3617 from OpenNeuroOrg/web-uploader-dropped-object-fix
fix(worker): Skip reuploaded but previously dropped annex objects
2 parents 6e49fd4 + 662b5a3 commit 62f86de

File tree

1 file changed

+16
-0
lines changed
  • services/datalad/datalad_service/handlers

1 file changed

+16
-0
lines changed

services/datalad/datalad_service/handlers/upload.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import pathlib
4+
import re
45
import aioshutil
56

67
import falcon
@@ -9,6 +10,10 @@
910
from datalad_service.common.git import git_commit
1011
from datalad_service.common.user import get_user_info
1112

13+
annex_key_re = re.compile(
14+
r'^(?P<backend>[A-Z0-9]+)-s(?P<size>[0-9]+)--(?P<hash>[a-f0-9]+)'
15+
)
16+
1217

1318
async def move_files(upload_path, dataset_path):
1419
for filename in pathlib.Path(upload_path).glob('**/*'):
@@ -17,6 +22,17 @@ async def move_files(upload_path, dataset_path):
1722
dataset_path, os.path.relpath(filename, start=upload_path)
1823
)
1924
pathlib.Path(target).parent.mkdir(parents=True, exist_ok=True)
25+
# Avoid reuploading dropped files
26+
if os.path.islink(target):
27+
link_path = os.readlink(target)
28+
annex_key = os.path.basename(link_path)
29+
match = annex_key_re.match(annex_key)
30+
if match:
31+
key_size = int(match.group('size'))
32+
source_size = os.path.getsize(filename)
33+
if key_size == source_size:
34+
# This is the same size file, we can skip moving it
35+
continue
2036
await aioshutil.move(str(filename), target)
2137

2238

0 commit comments

Comments
 (0)