diff --git a/include/linuxdeploy/core/desktopfile.h b/include/linuxdeploy/core/desktopfile.h index 23bc72d..385bdea 100644 --- a/include/linuxdeploy/core/desktopfile.h +++ b/include/linuxdeploy/core/desktopfile.h @@ -33,7 +33,8 @@ namespace linuxdeploy { DesktopFile(); // construct from existing desktop file - // file must exist, otherwise std::runtime_error is thrown + // if the file exists, it will be read using DesktopFileReader + // if reading fails, exceptions will be thrown (see DesktopFileReader for more information) explicit DesktopFile(const boost::filesystem::path& path); // construct by reading an existing stream diff --git a/src/core/desktopfile.cpp b/src/core/desktopfile.cpp index 40258a4..1f17a25 100644 --- a/src/core/desktopfile.cpp +++ b/src/core/desktopfile.cpp @@ -36,8 +36,10 @@ namespace linuxdeploy { DesktopFile::DesktopFile() : d(std::make_shared()) {} DesktopFile::DesktopFile(const bf::path& path) : DesktopFile() { - // will throw exceptions in case of issues - read(path); + if (bf::exists(path)) { + // will throw exceptions in case of issues + read(path); + } }; DesktopFile::DesktopFile(std::istream& is) : DesktopFile() { diff --git a/tests/core/test_desktopfile.cpp b/tests/core/test_desktopfile.cpp index 09c86d2..afdcbcf 100644 --- a/tests/core/test_desktopfile.cpp +++ b/tests/core/test_desktopfile.cpp @@ -66,7 +66,8 @@ TEST_F(DesktopFileFixture, testDefaultConstructor) { } TEST_F(DesktopFileFixture, testPathConstructor) { - EXPECT_THROW(DesktopFile("/a/b/c/d/e/f/g/h/1/2/3/4/5/6/7/8"), std::invalid_argument); + DesktopFile nonExistingPath("/a/b/c/d/e/f/g/h/1/2/3/4/5/6/7/8"); + EXPECT_TRUE(nonExistingPath.isEmpty()); DesktopFile emptyFile("/dev/null"); EXPECT_TRUE(emptyFile.isEmpty());