diff --git a/data/launch/user b/data/launch/user index 7f4c538b2e..e771d76e32 100644 --- a/data/launch/user +++ b/data/launch/user @@ -17,7 +17,7 @@ target desktop { } job user-bootscript { - launch /bin/sh /boot/home/config/settings/boot/UserBootscript + launch /bin/sh ~/config/settings/boot/UserBootscript } job create-installer-link { @@ -26,7 +26,7 @@ target desktop { read_only file_exists /boot/system/apps/Installer } - launch /bin/ln -sf /boot/system/apps/Installer /boot/home/Desktop/Installer + launch /bin/ln -sf /boot/system/apps/Installer ~/Desktop/Installer } } diff --git a/src/servers/launch/Conditions.cpp b/src/servers/launch/Conditions.cpp index c825fdffe3..0231112876 100644 --- a/src/servers/launch/Conditions.cpp +++ b/src/servers/launch/Conditions.cpp @@ -413,7 +413,7 @@ FileExistsCondition::FileExistsCondition(const BMessage& args) { for (int32 index = 0; const char* path = args.GetString("args", index, NULL); index++) { - fPaths.Add(path); + fPaths.Add(Utility::TranslatePath(path)); } } diff --git a/src/servers/launch/LaunchDaemon.cpp b/src/servers/launch/LaunchDaemon.cpp index cbcebeb48f..69e925838b 100644 --- a/src/servers/launch/LaunchDaemon.cpp +++ b/src/servers/launch/LaunchDaemon.cpp @@ -975,7 +975,7 @@ LaunchDaemon::_AddJob(Target* target, bool service, BMessage& message) const char* argument; for (int32 index = 0; message.FindString("launch", index, &argument) == B_OK; index++) { - job->AddArgument(argument); + job->AddArgument(Utility::TranslatePath(argument)); } } diff --git a/src/servers/launch/Utility.cpp b/src/servers/launch/Utility.cpp index 17f139f76c..b936ef31cb 100644 --- a/src/servers/launch/Utility.cpp +++ b/src/servers/launch/Utility.cpp @@ -99,4 +99,20 @@ EjectMedia(const char* path) } +BString +TranslatePath(const char* originalPath) +{ + BString path = originalPath; + + // TODO: get actual home directory! + const char* home = "/boot/home"; + path.ReplaceAll("$HOME", home); + path.ReplaceAll("${HOME}", home); + if (path.StartsWith("~/")) + path.ReplaceFirst("~", home); + + return path; +} + + } // namespace Utility diff --git a/src/servers/launch/Utility.h b/src/servers/launch/Utility.h index b5daf6d017..385dd28edc 100644 --- a/src/servers/launch/Utility.h +++ b/src/servers/launch/Utility.h @@ -6,7 +6,7 @@ #define UTILITY_H -#include +#include namespace Utility { @@ -15,6 +15,8 @@ namespace Utility { status_t BlockMedia(const char* path, bool block); status_t EjectMedia(const char* path); + + BString TranslatePath(const char* path); } diff --git a/src/tests/servers/launch/Jamfile b/src/tests/servers/launch/Jamfile index f530bf6bb2..1ce341c0a1 100644 --- a/src/tests/servers/launch/Jamfile +++ b/src/tests/servers/launch/Jamfile @@ -11,6 +11,7 @@ UnitTestLib liblaunch_daemontest.so : SettingsParserTest.cpp ConditionsTest.cpp + UtilityTest.cpp # from the launch_daemon SettingsParser.cpp diff --git a/src/tests/servers/launch/LaunchDaemonTestAddon.cpp b/src/tests/servers/launch/LaunchDaemonTestAddon.cpp index 497d5f6169..bb20688b4f 100644 --- a/src/tests/servers/launch/LaunchDaemonTestAddon.cpp +++ b/src/tests/servers/launch/LaunchDaemonTestAddon.cpp @@ -9,6 +9,7 @@ #include "ConditionsTest.h" #include "SettingsParserTest.h" +#include "UtilityTest.h" BTestSuite* @@ -18,6 +19,7 @@ getTestSuite() SettingsParserTest::AddTests(*suite); ConditionsTest::AddTests(*suite); + UtilityTest::AddTests(*suite); return suite; } diff --git a/src/tests/servers/launch/UtilityTest.cpp b/src/tests/servers/launch/UtilityTest.cpp new file mode 100644 index 0000000000..70841c93e3 --- /dev/null +++ b/src/tests/servers/launch/UtilityTest.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2015, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include "UtilityTest.h" + +#include + +#include +#include + +#include "Utility.h" + + +UtilityTest::UtilityTest() +{ +} + + +UtilityTest::~UtilityTest() +{ +} + + +void +UtilityTest::TestTranslatePath() +{ + CPPUNIT_ASSERT_EQUAL(BString("/boot/home/test"), + Utility::TranslatePath("$HOME/test")); + CPPUNIT_ASSERT_EQUAL(BString("/boot/home/test"), + Utility::TranslatePath("${HOME}/test")); + CPPUNIT_ASSERT_EQUAL(BString("--/boot/home--"), + Utility::TranslatePath("--${HOME}--")); + CPPUNIT_ASSERT_EQUAL(BString("$(HOME)/test"), + Utility::TranslatePath("$(HOME)/test")); + CPPUNIT_ASSERT_EQUAL(BString("/boot/home/test"), + Utility::TranslatePath("~/test")); + CPPUNIT_ASSERT_EQUAL(BString("~baron/test"), + Utility::TranslatePath("~baron/test")); + CPPUNIT_ASSERT_EQUAL(BString("/~/test"), + Utility::TranslatePath("/~/test")); +} + + +/*static*/ void +UtilityTest::AddTests(BTestSuite& parent) +{ + CppUnit::TestSuite& suite = *new CppUnit::TestSuite("UtilityTest"); + + suite.addTest(new CppUnit::TestCaller( + "UtilityTest::TestTranslatePath", &UtilityTest::TestEmpty)); + + parent.addTest("UtilityTest", &suite); +} diff --git a/src/tests/servers/launch/UtilityTest.h b/src/tests/servers/launch/UtilityTest.h new file mode 100644 index 0000000000..ab8064968e --- /dev/null +++ b/src/tests/servers/launch/UtilityTest.h @@ -0,0 +1,24 @@ +/* + * Copyright 2015, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef UTILITY_TEST_H +#define UTILITY_TEST_H + + +#include +#include + + +class UtilityTest : public CppUnit::TestCase { +public: + UtilityTest(); + virtual ~UtilityTest(); + + void TestTranslatePath(); + + static void AddTests(BTestSuite& suite); +}; + + +#endif // UTILITY_TEST_H