# Can we prefer local package and fallback to url package

**URL:** <https://forums.swift.org/t/can-we-prefer-local-package-and-fallback-to-url-package/55676>\
**Category:** Discussion\
**Tags:** packagemanager\
**Created:** [March 2, 2022, 8:09am UTC](https://forums.swift.org/t/can-we-prefer-local-package-and-fallback-to-url-package/55676 "2022-03-02T08:09:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Kyle-Ye](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kyle-ye/32/19686_2.png) [@Kyle-Ye](https://forums.swift.org/u/Kyle-Ye)\
**Post date:** [April 5, 2022, 1:36pm UTC](https://forums.swift.org/t/can-we-prefer-local-package-and-fallback-to-url-package/55676/2 "2022-04-05T13:36:25Z")

</div>

Inspired by this PR, found another workaround. [Enable library evolution for SwiftDocC library via a conditional by franklinsch · Pull Request #123 · apple/swift-docc · GitHub](https://github.com/apple/swift-docc/pull/123)

We can use `#filePath` and `deletingLastPathComponent` API to workaround with the sandbox limitation.

> Note: ".." will not work, use `deletingLastPathComponent` instead

```swift
extension Package.Dependency {
    static func package(
        preferLocal: Bool = true,
        name: String,
        location: String? = nil,
        url: String,
        _ requirement: Package.Dependency.Requirement) -> Package.Dependency {
        let manifestLocation = URL(fileURLWithPath: #filePath)
        let location = location ?? name
        let packageLocation = manifestLocation
            .deletingLastPathComponent()
            .deletingLastPathComponent()
            .appendingPathComponent(location)
        if preferLocal, FileManager.default.fileExists(atPath: packageLocation.path) {
            return .package(path: packageLocation.path)
        } else {
            return .package(url: url, requirement)
        }
    }
}

```

Using the above method, we could check the existence of some folder in the parent directory of the Package without adding `--disable-sandbox` flag. Is this a SPM sandbox bug or a known use case? cc @tomerd

---

_[View the full topic](https://forums.swift.org/t/can-we-prefer-local-package-and-fallback-to-url-package/55676)._
