Skip to content

Commit 6f7a247

Browse files
authored
Merge pull request #3130 from antgonza/insert_filepaths-copy-files-
making sure the files are copied when copy in insert_filepaths
2 parents f7dd269 + 8194005 commit 6f7a247

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

qiita_db/test/test_util.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ def test_insert_filepaths_copy(self):
228228
qdb.sql_connection.TRN.add(
229229
"SELECT last_value FROM qiita.filepath_filepath_id_seq")
230230
exp_new_id = 1 + qdb.sql_connection.TRN.execute_fetchflatten()[0]
231-
obs = qdb.util.insert_filepaths([(fp, 1)], 2, "raw_data", copy=True)
231+
obs = qdb.util.insert_filepaths([(fp, 1)], 2, "raw_data",
232+
move_files=False, copy=True)
232233
self.assertEqual(obs, [exp_new_id])
233234

234235
# Check that the files have been copied correctly
@@ -247,6 +248,19 @@ def test_insert_filepaths_copy(self):
247248
exp = [[exp_new_id, exp_fp, 1, '852952723', 1, 5, 1]]
248249
self.assertEqual(obs, exp)
249250

251+
# let's do that again but with move_files = True
252+
exp_new_id += 1
253+
obs = qdb.util.insert_filepaths([(fp, 1)], 2, "raw_data",
254+
move_files=True, copy=True)
255+
self.assertEqual(obs, [exp_new_id])
256+
257+
# Check that the files have been copied correctly
258+
exp_fp = join(qdb.util.get_db_files_base_dir(), "raw_data",
259+
"2_%s" % basename(fp))
260+
self.assertTrue(exists(exp_fp))
261+
self.assertTrue(exists(fp))
262+
self.files_to_remove.append(exp_fp)
263+
250264
qdb.util.purge_filepaths()
251265

252266
def test_insert_filepaths_string(self):

qiita_db/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def insert_filepaths(filepaths, obj_id, table, move_files=True, copy=False):
610610
dd_id, mp, subdir = get_mountpoint(table, retrieve_subdir=True)[0]
611611
base_fp = join(get_db_files_base_dir(), mp)
612612

613-
if move_files:
613+
if move_files or copy:
614614
db_path = partial(join, base_fp)
615615
if subdir:
616616
# Generate the new filepaths, format:

0 commit comments

Comments
 (0)