Don't require desktop file's path to exist

This commit is contained in:
TheAssassin 2018-11-09 21:26:23 +01:00
parent aaaca8b321
commit 574a883733
3 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -36,8 +36,10 @@ namespace linuxdeploy {
DesktopFile::DesktopFile() : d(std::make_shared<PrivateData>()) {}
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() {

View File

@ -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());