# File::copyDirectoryTo doesn't preserve symlinks (macOS)

**URL:** <https://forum.juce.com/t/file-copydirectoryto-doesnt-preserve-symlinks-macos/40772>\
**Category:** MacOSX and iOS\
**Created:** [July 17, 2020, 7:44am UTC](https://forum.juce.com/t/file-copydirectoryto-doesnt-preserve-symlinks-macos/40772 "2020-07-17T07:44:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ans](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ans/32/617_2.png) [@ans](https://forum.juce.com/u/ans)\
**Post date:** [July 17, 2020, 7:44am UTC](https://forum.juce.com/t/file-copydirectoryto-doesnt-preserve-symlinks-macos/40772/1 "2020-07-17T07:44:18Z")

</div>

Copying a bundle or framework that has symlinks inside does not preserve the symbolic links. Instead physical deep copies are made. This pretty much renders Juce incapable of perfoming deployment and installation tasks.

I see that **File::copyDirectoryTo** uses **NSFileManager** internally, but somehow, according to Apple’s documentation, there doesn’t seem to be an option to preserve symlinks, so it is unclear how to fix this.

Isn’t there a system call on macOS that mimics a copy with Finder? What am I missing?

---

<div class="post-metadata">

**Author:** ![ans](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ans/32/617_2.png) [@ans](https://forum.juce.com/u/ans)\
**Post date:** [July 17, 2020, 8:12am UTC](https://forum.juce.com/t/file-copydirectoryto-doesnt-preserve-symlinks-macos/40772/2 "2020-07-17T08:12:27Z")

</div>

An experiment showed that using **File::copyFileTo** to copy a bundle or framework does the trick.

So if an application is required to determine whether to use **copyFileTo** or **copyDirectoryTo** , the remedy is to check for **isBundle()** first for any top-level item to copy.

---

<div class="post-metadata">

**Author:** ![ans](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ans/32/617_2.png) [@ans](https://forum.juce.com/u/ans)\
**Post date:** [July 17, 2020, 9:05am UTC](https://forum.juce.com/t/file-copydirectoryto-doesnt-preserve-symlinks-macos/40772/3 "2020-07-17T09:05:19Z")

</div>

Well, it turns out that **isBundle()** does not reliably recognize bundles you have created from files and folders yourself. I don’t know how common this is, but I’m building apps and bundles with automated build scripts a lot.

If you’re doing this also, you can use the following function to tell whether a File is to be copied with copyDirectoryTo vs. copyFileTo:

```
bool isCopiedAsDirectory (const File& source)
{
    if (! source.isDirectory())
        return false;
    
#if JUCE_MAC
    if (source.isBundle())
        return false;
    
    static const StringArray bundles =
        { ".app", ".bundle", ".framework", ".component", ".vst", ".vst3", ".aaxplugin", ".pkg", ".mpkg" };

    if (bundles.indexOf (source.getFileExtension()) >= 0)
        return false;
#endif
    return true;
}
```
