Skip to content

Commit

Permalink
Fixed issue that appeared when trying to remove temporary folder from…
Browse files Browse the repository at this point in the history
… different file systems (#2473)

* install_sct: replaced hard-coded bin by $BIN_DIR

* sct_download_data: Now copying folder instead of moving it

Also using distutils instead of shutil, to copy directories that might
not be empty.
Addressed issue #2472

* sct_download_data: No more removal of existing file in dest folder
  • Loading branch information
jcohenadad authored Oct 4, 2019
1 parent eb65a84 commit 0dbbcbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
8 changes: 4 additions & 4 deletions install_sct
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ fi

## Create launchers for Python scripts
echo -e "\nCreating launchers for Python scripts..."
mkdir -p $SCT_DIR/bin
mkdir -p $SCT_DIR/$BIN_DIR
for file in $SCT_DIR/python/envs/venv_sct/bin/*sct*; do
cp "$file" "$SCT_DIR/bin/"
cp "$file" "$SCT_DIR/$BIN_DIR/"
res=$?
if [[ $res != 0 ]]; then
echo "\nProblem creating launchers!"
Expand All @@ -503,8 +503,8 @@ done

## Create symbolic links for Shell scripts (-f: overwrite if exists)
echo -e "\nCreating symbolic links for Shell scripts..."
ln -s -f $SCT_DIR/shell/sct_run_batch.sh $SCT_DIR/bin/sct_run_batch
ln -s -f $SCT_DIR/shell/_run_with_log.sh $SCT_DIR/bin/_run_with_log.sh
ln -s -f $SCT_DIR/shell/sct_run_batch.sh $SCT_DIR/$BIN_DIR/sct_run_batch
ln -s -f $SCT_DIR/shell/_run_with_log.sh $SCT_DIR/$BIN_DIR/_run_with_log.sh
res=$?
if [[ $res != 0 ]]; then
echo "\nProblem creating symlinks!"
Expand Down
25 changes: 13 additions & 12 deletions scripts/sct_download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import tarfile
import tempfile
import zipfile
from shutil import rmtree, move, copytree
from shutil import rmtree
from distutils.dir_util import copy_tree

import requests
from requests.adapters import HTTPAdapter
Expand Down Expand Up @@ -144,24 +145,24 @@ def main(args=None):
extracted_files_paths.append(os.path.join(os.path.abspath(dest_tmp_folder), extracted_file))

# Check if files and folder already exists
sct.printv('\nCheck if files or folder already exists on the destination path...', verbose)
sct.printv('\nCheck if folder already exists on the destination path...', verbose)
for data_extracted_name in extracted_files:
fullpath_dest = os.path.join(dest_folder, data_extracted_name)
if os.path.isdir(fullpath_dest):
sct.printv("Folder {} already exists. Removing it...".format(data_extracted_name), 1, 'warning')
rmtree(fullpath_dest)
elif os.path.isfile(fullpath_dest):
sct.printv("File {} already exists. Removing it...".format(data_extracted_name), 1, 'warning')
os.remove(fullpath_dest)

# Destination path
for source_path in extracted_files_paths:
# Move the content of source to destination
move(source_path, dest_folder, copy_function=copytree)

sct.printv('\nRemove temporary files...', verbose)
os.remove(tmp_file)
rmtree(dest_tmp_folder)
# for source_path in extracted_files_paths:
# Copy the content of source to destination (and create destination folder)
copy_tree(dest_tmp_folder, dest_folder)

sct.printv("\nRemove temporary folders...", verbose)
try:
rmtree(os.path.split(tmp_file)[0])
rmtree(dest_tmp_folder)
except Exception as error:
print("Cannot remove temp folder: " + repr(error))

sct.printv('Done!\n', verbose)
return 0
Expand Down

0 comments on commit 0dbbcbf

Please sign in to comment.