Skip to content

Commit 5802656

Browse files
committed
temp workaround for issue #449
1 parent bab9898 commit 5802656

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

Plugins/AWSLambdaPackager/Plugin.swift

+23-5
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,29 @@ struct AWSLambdaPackager: CommandPlugin {
249249
let resourcesDirectoryName = artifactURL.lastPathComponent
250250
let relocatedResourcesDirectory = workingDirectory.appending(path: resourcesDirectoryName)
251251
if FileManager.default.fileExists(atPath: artifactURL.path()) {
252-
try FileManager.default.copyItem(
253-
atPath: artifactURL.path(),
254-
toPath: relocatedResourcesDirectory.path()
255-
)
256-
arguments.append(resourcesDirectoryName)
252+
do {
253+
try FileManager.default.copyItem(
254+
atPath: artifactURL.path(),
255+
toPath: relocatedResourcesDirectory.path()
256+
)
257+
arguments.append(resourcesDirectoryName)
258+
} catch let error as CocoaError {
259+
260+
// On Linux, when the build has been done with Docker,
261+
// the source file are owned by root
262+
// this causes a permission error **after** the files have been copied
263+
// see https://github.com/swift-server/swift-aws-lambda-runtime/issues/449
264+
// see https://forums.swift.org/t/filemanager-copyitem-on-linux-fails-after-copying-the-files/77282
265+
266+
// because this error happens after the files have been copied, we can ignore it
267+
// this code checks if the destination file exists
268+
// if they do, just ignore error, otherwise throw it up to the caller.
269+
if !(error.code == CocoaError.Code.fileWriteNoPermission
270+
&& FileManager.default.fileExists(atPath: relocatedResourcesDirectory.path()))
271+
{
272+
throw error
273+
} // else just ignore it
274+
}
257275
}
258276
}
259277

0 commit comments

Comments
 (0)