Skip to content

Commit f537236

Browse files
authored
Fix the problem with duplicated frames in case of "share" (#735)
* Fix the problem with duplicated frames in case of "share". * Fix a case when the code works incorrectly /a/b/c /a/b/c0 Previously only /a/b/c will be in output but should be both.
1 parent 1ec89b5 commit f537236

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

cvat/apps/engine/task.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,25 @@ def _save_task_to_db(db_task):
142142

143143
def _validate_data(data):
144144
share_root = settings.SHARE_ROOT
145-
server_files = {
146-
'dirs': [],
147-
'files': [],
148-
}
145+
server_files = []
149146

150147
for path in data["server_files"]:
151148
path = os.path.normpath(path).lstrip('/')
152149
if '..' in path.split(os.path.sep):
153150
raise ValueError("Don't use '..' inside file paths")
154151
full_path = os.path.abspath(os.path.join(share_root, path))
155-
if 'directory' == get_mime(full_path):
156-
server_files['dirs'].append(path)
157-
else:
158-
server_files['files'].append(path)
159152
if os.path.commonprefix([share_root, full_path]) != share_root:
160153
raise ValueError("Bad file path: " + path)
161-
162-
# Remove directories if other files from them exists in server files
163-
data['server_files'] = server_files['files'] + [ dir_name for dir_name in server_files['dirs']
164-
if not [ f_name for f_name in server_files['files'] if f_name.startswith(dir_name)]]
154+
server_files.append(path)
155+
156+
server_files.sort(reverse=True)
157+
# The idea of the code is trivial. After sort we will have files in the
158+
# following order: 'a/b/c/d/2.txt', 'a/b/c/d/1.txt', 'a/b/c/d', 'a/b/c'
159+
# Let's keep all items which aren't substrings of the previous item. In
160+
# the example above only 2.txt and 1.txt files will be in the final list.
161+
# Also need to correctly handle 'a/b/c0', 'a/b/c' case.
162+
data['server_files'] = [v[1] for v in zip([""] + server_files, server_files)
163+
if not os.path.dirname(v[0]).startswith(v[1])]
165164

166165
def count_files(file_mapping, counter):
167166
for rel_path, full_path in file_mapping.items():

0 commit comments

Comments
 (0)