Skip to content

[Serialization] Ignore filesystem errors when loading modules. #4547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ openModuleFiles(StringRef DirName, StringRef ModuleFilename,
return std::error_code();
}

static std::error_code
static bool
findModule(ASTContext &ctx, AccessPathElem moduleID,
std::unique_ptr<llvm::MemoryBuffer> &moduleBuffer,
std::unique_ptr<llvm::MemoryBuffer> &moduleDocBuffer,
Expand Down Expand Up @@ -110,8 +110,8 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
moduleBuffer, moduleDocBuffer,
scratch);
}
if (!err || err != std::errc::no_such_file_or_directory)
return err;
if (!err)
return true;
}

{
Expand All @@ -127,20 +127,20 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
archFile.str(), archDocFile.str(),
moduleBuffer, moduleDocBuffer,
scratch);
if (!err || err != std::errc::no_such_file_or_directory)
return err;
if (!err)
return true;
}
}

// If we're not allowed to look in the runtime library import path, stop.
if (ctx.SearchPathOpts.SkipRuntimeLibraryImportPath)
return std::make_error_code(std::errc::no_such_file_or_directory);
return false;

// Search the runtime import path.
isFramework = false;
return openModuleFiles(ctx.SearchPathOpts.RuntimeLibraryImportPath,
moduleFilename.str(), moduleDocFilename.str(),
moduleBuffer, moduleDocBuffer, scratch);
return !openModuleFiles(ctx.SearchPathOpts.RuntimeLibraryImportPath,
moduleFilename.str(), moduleDocFilename.str(),
moduleBuffer, moduleDocBuffer, scratch);
}

FileUnit *SerializedModuleLoader::loadAST(
Expand Down Expand Up @@ -378,14 +378,8 @@ Module *SerializedModuleLoader::loadModule(SourceLoc importLoc,

// Otherwise look on disk.
if (!moduleInputBuffer) {
if (std::error_code err = findModule(Ctx, moduleID, moduleInputBuffer,
moduleDocInputBuffer,
isFramework)) {
if (err != std::errc::no_such_file_or_directory) {
Ctx.Diags.diagnose(moduleID.second, diag::sema_opening_import,
moduleID.first, err.message());
}

if (!findModule(Ctx, moduleID, moduleInputBuffer, moduleDocInputBuffer,
isFramework)) {
return nullptr;
}

Expand Down
10 changes: 10 additions & 0 deletions test/Serialization/load-file-permissions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: if [[ -d %t ]]; then chmod -R u+rwx %t && rm -rf %t; fi
// RUN: mkdir -p %t/good
// RUN: mkdir %t/bad
// RUN: chmod a-rx %t/bad
// RUN: %target-swift-frontend -emit-module -o %t/good %S/../Inputs/empty.swift
// RUN: not %target-swift-frontend %s -parse -I %t/bad -I %t/good -show-diagnostics-after-fatal 2>&1 | %FileCheck %s
// RUN: not %target-swift-frontend %s -parse -I %t/good -I %t/bad -show-diagnostics-after-fatal 2>&1 | %FileCheck %s

import empty // CHECK-NOT: empty
import ThisOneReallyDoesNotExist // CHECK: [[@LINE]]:{{[0-9]+}}: error: no such module 'ThisOneReallyDoesNotExist'