Skip to content

Commit 5b01cb9

Browse files
committed
fix untar
1 parent 1753753 commit 5b01cb9

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

fastcore/xtras.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ def loads_multi(s:str):
151151
def untar_dir(fname, dest):
152152
"untar `file` into `dest`"
153153
with tempfile.TemporaryDirectory(dir='.') as d:
154-
shutil.unpack_archive(fname, d)
155-
ls = Path(d).ls()
154+
out = Path(d)/'out'
155+
out.mkdir()
156+
shutil.unpack_archive(fname, out)
157+
ls = out.ls()
156158
if len(ls) == 1: shutil.move(str(ls[0]), dest)
157-
else: shutil.move(str(d), dest/remove_suffix(Path(fname).stem, '.tar'))
159+
else: shutil.move(str(out), dest/remove_suffix(Path(fname).stem, '.tar'))
158160

159161
# Cell
160162
def repo_details(url):

nbs/03_xtras.ipynb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@
618618
{
619619
"data": {
620620
"text/plain": [
621-
"['d', 'e', 'h', 'g', 'b', 'a', 'c', 'f']"
621+
"['c', 'b', 'e', 'f', 'g', 'a', 'd', 'h']"
622622
]
623623
},
624624
"execution_count": null,
@@ -1010,10 +1010,12 @@
10101010
"def untar_dir(fname, dest):\n",
10111011
" \"untar `file` into `dest`\"\n",
10121012
" with tempfile.TemporaryDirectory(dir='.') as d:\n",
1013-
" shutil.unpack_archive(fname, d)\n",
1014-
" ls = Path(d).ls()\n",
1013+
" out = Path(d)/'out'\n",
1014+
" out.mkdir()\n",
1015+
" shutil.unpack_archive(fname, out)\n",
1016+
" ls = out.ls()\n",
10151017
" if len(ls) == 1: shutil.move(str(ls[0]), dest)\n",
1016-
" else: shutil.move(str(d), dest/remove_suffix(Path(fname).stem, '.tar'))"
1018+
" else: shutil.move(str(out), dest/remove_suffix(Path(fname).stem, '.tar'))"
10171019
]
10181020
},
10191021
{
@@ -1295,7 +1297,8 @@
12951297
"outputs": [],
12961298
"source": [
12971299
"for suf in '.pkl','.bz2','.gz':\n",
1298-
" # delete=False is added for Windows. https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file\n",
1300+
" # delete=False is added for Windows\n",
1301+
" # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file\n",
12991302
" with tempfile.NamedTemporaryFile(suffix=suf, delete=False) as f:\n",
13001303
" fn = Path(f.name)\n",
13011304
" save_pickle(fn, 't')\n",

0 commit comments

Comments
 (0)