Repository: conda/conda-build

Issue:
Bug when building from archive
This happens with conda-build 3.0.30 and anaconda 4.4 (I'm stuck on redhat 5), with the `meta.yaml`
```
package:
    name: test
    version: 1

source:
    url: dir.tar.bz2
```

and a `dir.tar.bz2` archive that contains the `dir` directory created with
```
mkdir -p dir/dir
touch dir/e
```

I get the following error
```
Traceback (most recent call last):
  File "/scratch/anaconda/bin/conda-build", line 11, in <module>
    sys.exit(main())
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/cli/main_build.py", line 388, in main
    execute(sys.argv[1:])
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/cli/main_build.py", line 379, in execute
    verify=args.verify)
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/api.py", line 187, in build
    need_source_download=need_source_download, config=config, variants=variants)
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/build.py", line 1801, in build_tree
    notest=notest,
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/build.py", line 1026, in build
    try_download(m, no_download_source=False, raise_error=True)
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/render.py", line 417, in try_download
    source.provide(metadata)
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/source.py", line 623, in provide
    timeout=metadata.config.timeout, locking=metadata.config.locking)
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/source.py", line 160, in unpack
    hoist_single_extracted_folder(folder)
  File "/scratch/anaconda/lib/python2.7/site-packages/conda_build/source.py", line 124, in hoist_single_extracted_folder
    shutil.move(os.path.join(nested_folder, thing), os.path.join(parent, thing))
  File "/scratch/anaconda/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/scratch/anaconda/lib/python2.7/shutil.py", line 130, in copy2
    copyfile(src, dst)
  File "/scratch/anaconda/lib/python2.7/shutil.py", line 82, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: u'/scratch/conda-bld/tmpnpK36g/dir/dir/e'
```


Discussion:
Thanks for figuring that out.  I'll fix it for the next bugfix release.

Resolving patch:
diff --git a/conda_build/source.py b/conda_build/source.py
--- a/conda_build/source.py
+++ b/conda_build/source.py
@@ -119,13 +119,15 @@ def hoist_single_extracted_folder(nested_folder):
     know exactly what that folder is called."""
     flist = os.listdir(nested_folder)
     parent = os.path.dirname(nested_folder)
+    nested_folders_to_remove = [nested_folder]
     for thing in flist:
         if not os.path.isdir(os.path.join(parent, thing)):
             shutil.move(os.path.join(nested_folder, thing), os.path.join(parent, thing))
         else:
             copy_into(os.path.join(nested_folder, thing), os.path.join(parent, thing))
-            nested_folder = os.path.join(nested_folder, thing)
-    rm_rf(nested_folder)
+            nested_folders_to_remove.append(os.path.join(nested_folder, thing))
+    for folder in nested_folders_to_remove:
+        rm_rf(folder)
 
 
 def unpack(source_dict, src_dir, cache_folder, recipe_path, croot, verbose=False,


Test patch:
diff --git a/tests/test_source.py b/tests/test_source.py
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -109,7 +109,7 @@ def test_hoist_same_name(testing_workdir):
     os.makedirs(testdir)
     with open(os.path.join(testdir, 'somefile'), 'w') as f:
         f.write('weeeee')
-    source.hoist_single_extracted_folder(outer_dir)
+    source.hoist_single_extracted_folder(testdir)
     assert os.path.isfile(os.path.join(outer_dir, 'somefile'))
     assert not os.path.isdir(testdir)