Skip to content

Commit

Permalink
Fix an error printed out when install_location file is missing
Browse files Browse the repository at this point in the history
The app will still run, but we must not print out anything in that case.
  • Loading branch information
vitek-karas authored and github-actions committed Jul 26, 2021
1 parent 46b249d commit 4b31118
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,38 @@ public void InstallLocationFile_ReallyLongInstallPathIsParsedCorrectly()
}
}

[Fact]
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void InstallLocationFile_MissingFile()
{
var fixture = sharedTestState.PortableAppFixture.Copy();

var appExe = fixture.TestProject.AppExe;
string testArtifactsPath = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "missingInstallLocation"));
using (new TestArtifact(testArtifactsPath))
using (var testOnlyProductBehavior = TestOnlyProductBehavior.Enable(appExe))
{
Directory.CreateDirectory(testArtifactsPath);

string directory = Path.Combine(testArtifactsPath, "installLocationOverride");
Directory.CreateDirectory(directory);
string nonExistentLocationFile = Path.Combine(directory, "install_location");
string defaultInstallLocation = Path.Combine(testArtifactsPath, "defaultInstallLocation");

Command.Create(appExe)
.CaptureStdErr()
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.InstallLocationFilePath,
nonExistentLocationFile)
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.DefaultInstallPath,
defaultInstallLocation)
.DotNetRoot(null)
.Execute()
.Should().NotHaveStdErrContaining("install_location");
}
}

public class SharedTestState : IDisposable
{
public string BaseDirectory { get; }
Expand Down
10 changes: 9 additions & 1 deletion src/native/corehost/hostmisc/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,15 @@ bool pal::get_dotnet_self_registered_dir(pal::string_t* recv)
FILE* install_location_file = pal::file_open(install_location_file_path, "r");
if (install_location_file == nullptr)
{
trace::error(_X("The install_location file ['%s'] failed to open: %s."), install_location_file_path.c_str(), pal::strerror(errno));
if (errno == ENOENT)
{
trace::verbose(_X("The install_location file ['%s'] does not exist - skipping."), install_location_file_path.c_str());
}
else
{
trace::error(_X("The install_location file ['%s'] failed to open: %s."), install_location_file_path.c_str(), pal::strerror(errno));
}

return false;
}

Expand Down

0 comments on commit 4b31118

Please sign in to comment.