Repository: conan-io/conan

Issue:
Error with v1.4
Hello,

I have the following Conan recipe

```
# cat conanfile.txt 

[requires]
bitprim-node-cint/0.10.0@bitprim/testing
[generators]
cmake
[options]
bitprim-node-cint:shared=True
bitprim-node-cint:currency=BCH
[imports]
bin, *.dll    -> .
lib, *.so    -> .
lib, *.dylib    -> .
``` 

When I execute: `conan install .` 
I get the following errors:

```
...
PROJECT: Generator txt created conanbuildinfo.txt
PROJECT: Generated conaninfo.txt
Traceback (most recent call last):
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/command.py", line 1182, in run
    method(args[0][1:])
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/command.py", line 325, in install
    install_folder=args.install_folder)
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/conan_api.py", line 77, in wrapper
    return f(*args, **kwargs)
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/conan_api.py", line 465, in install
    no_imports=no_imports)
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/manager.py", line 344, in install
    run_imports(conanfile, install_folder, output)
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/importer.py", line 82, in run_imports
    conanfile.imports()
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/loader_parse.py", line 184, in imports
    conan_file.copy(*import_params)
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/importer.py", line 160, in __call__
    excludes=excludes, keep_path=keep_path)
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/file_copier.py", line 83, in __call__
    self._link_folders(src, dst, link_folders)
  File "/home/fernando/.local/lib/python2.7/site-packages/conans/client/file_copier.py", line 149, in _link_folders
    os.symlink(link, dst_link)
OSError: [Errno 2] No such file or directory

ERROR: [Errno 2] No such file or directory
```

```
$ conan --version
Conan version 1.4.0

$ python --version
Python 2.7.15

$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	Fedora
Description:	Fedora release 28 (Twenty Eight)
Release:	28
Codename:	TwentyEight

```

It works fine with Conan 1.3.3.

Thanks and regards,
Fernando.


Discussion:
Totally seems a bug, will try to fix asap and release in 1.4.1. Thanks for reporting!

Resolving patch:
diff --git a/conans/client/file_copier.py b/conans/client/file_copier.py
--- a/conans/client/file_copier.py
+++ b/conans/client/file_copier.py
@@ -3,7 +3,7 @@
 import shutil
 from collections import defaultdict
 
-from conans import tools
+from conans.util.files import mkdir
 
 
 def report_copied_files(copied, output):
@@ -146,6 +146,7 @@ def _link_folders(src, dst, linked_folders):
                 pass
             # link is a string relative to linked_folder
             # e.j: os.symlink("test/bar", "./foo/test_link") will create a link to foo/test/bar in ./foo/test_link
+            mkdir(os.path.dirname(dst_link))
             os.symlink(link, dst_link)
         # Remove empty links
         for linked_folder in linked_folders:


Test patch:
diff --git a/conans/test/functional/file_copier_test.py b/conans/test/functional/file_copier_test.py
--- a/conans/test/functional/file_copier_test.py
+++ b/conans/test/functional/file_copier_test.py
@@ -101,6 +101,20 @@ def linked_relative_test(self):
         self.assertTrue(os.path.islink(symlink))
         self.assertTrue(load(os.path.join(symlink, "file.txt")), "Hello")
 
+    @unittest.skipUnless(platform.system() != "Windows", "Requires Symlinks")
+    def linked_folder_nested_test(self):
+        # https://github.com/conan-io/conan/issues/2959
+        folder1 = temp_folder()
+        sub1 = os.path.join(folder1, "lib/icu/60.2")
+        sub2 = os.path.join(folder1, "lib/icu/current")
+        os.makedirs(sub1)
+        os.symlink("60.2", sub2)  # @UndefinedVariable
+
+        folder2 = temp_folder()
+        copier = FileCopier(folder1, folder2)
+        copied = copier("*.cpp", links=True)
+        self.assertEqual(copied, [])
+
     def excludes_test(self):
         folder1 = temp_folder()
         sub1 = os.path.join(folder1, "subdir1")