From 5b0a1f3a3d389eea87ccbd1388a57306972f579b Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 7 Dec 2020 12:56:05 +0100 Subject: [PATCH 1/3] check shutil error for #294 --- dotdrop/importer.py | 18 +++++++++++------- tests-ng/import.sh | 32 ++++++++++++++++++++++++++++++++ tests.sh | 2 +- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/dotdrop/importer.py b/dotdrop/importer.py index 5abaf3d..dcb80c2 100644 --- a/dotdrop/importer.py +++ b/dotdrop/importer.py @@ -173,13 +173,17 @@ class Importer: if self.dry: self.log.dry('would copy {} to {}'.format(dst, srcf)) else: - # copy the file to the dotpath - if os.path.isdir(dst): - if os.path.exists(srcf): - shutil.rmtree(srcf) - shutil.copytree(dst, srcf) - else: - shutil.copy2(dst, srcf) + try: + # copy the file to the dotpath + if os.path.isdir(dst): + if os.path.exists(srcf): + shutil.rmtree(srcf) + shutil.copytree(dst, srcf) + else: + shutil.copy2(dst, srcf) + except shutil.Error as e: + why = e.args[0][0][2] + self.log.err('importing \"{}\" failed: {}'.format(dst, why)) return True diff --git a/tests-ng/import.sh b/tests-ng/import.sh index 854388e..40ca61d 100755 --- a/tests-ng/import.sh +++ b/tests-ng/import.sh @@ -101,6 +101,38 @@ cntpost=`find ${tmps}/dotfiles -type f | wc -l` [ "${cntpost}" != "${cntpre}" ] && echo "import issue" && exit 1 +####################################### +# import directory with named pipe + +cat > ${cfg} << _EOF +config: + backup: true + create: true + dotpath: dotfiles +dotfiles: +profiles: +_EOF + +# create the dotfile +d="${tmpd}/with_named_pipe" +mkdir -p ${d} +echo "file1" > ${d}/file1 +echo "fil2" > ${d}/file2 +mkfifo ${d}/fifo + +# import +cd ${ddpath} | ${bin} import -c ${cfg} -p p2 -V ${d} + +cat ${cfg} +tree ${tmps}/dotfiles + +# ensure exists and is not link +[ ! -d ${tmps}/dotfiles/${d} ] && echo "not a directory" && exit 1 +[ ! -e ${tmps}/dotfiles/${d}/file1 ] && echo "not exist" && exit 1 +[ ! -e ${tmps}/dotfiles/${d}/file2 ] && echo "not exist" && exit 1 + +cat ${cfg} | grep ${d} >/dev/null 2>&1 + ## CLEANING rm -rf ${tmps} ${tmpd} diff --git a/tests.sh b/tests.sh index 722f973..d98f76b 100755 --- a/tests.sh +++ b/tests.sh @@ -100,4 +100,4 @@ fi #fi ## done -echo "All test finished successfully in ${SECONDS}s" +echo "All test finished successfully" From 5c66a8ea838b07f5d7c8af7d26cf186fbb0de7f1 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 7 Dec 2020 13:00:17 +0100 Subject: [PATCH 2/3] fix error format --- dotdrop/importer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dotdrop/importer.py b/dotdrop/importer.py index dcb80c2..1f7a42b 100644 --- a/dotdrop/importer.py +++ b/dotdrop/importer.py @@ -182,8 +182,9 @@ class Importer: else: shutil.copy2(dst, srcf) except shutil.Error as e: + src = e.args[0][0][0] why = e.args[0][0][2] - self.log.err('importing \"{}\" failed: {}'.format(dst, why)) + self.log.err('importing \"{}\" failed: {}'.format(src, why)) return True From 1b37fa9085bba92a4b0263b7aa73dbd1d86c39f7 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 7 Dec 2020 13:27:52 +0100 Subject: [PATCH 3/3] fix tests --- tests-ng/import.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests-ng/import.sh b/tests-ng/import.sh index 40ca61d..81eb79c 100755 --- a/tests-ng/import.sh +++ b/tests-ng/import.sh @@ -123,9 +123,6 @@ mkfifo ${d}/fifo # import cd ${ddpath} | ${bin} import -c ${cfg} -p p2 -V ${d} -cat ${cfg} -tree ${tmps}/dotfiles - # ensure exists and is not link [ ! -d ${tmps}/dotfiles/${d} ] && echo "not a directory" && exit 1 [ ! -e ${tmps}/dotfiles/${d}/file1 ] && echo "not exist" && exit 1