launch_daemon: "file_exists" now resolves $HOME, and '~'.
This commit is contained in:
+2
-2
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define UTILITY_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ UnitTestLib liblaunch_daemontest.so :
|
||||
|
||||
SettingsParserTest.cpp
|
||||
ConditionsTest.cpp
|
||||
UtilityTest.cpp
|
||||
|
||||
# from the launch_daemon
|
||||
SettingsParser.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;
|
||||
}
|
||||
|
||||
@@ -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 <stdlib.h>
|
||||
|
||||
#include <cppunit/TestCaller.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
|
||||
#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>(
|
||||
"UtilityTest::TestTranslatePath", &UtilityTest::TestEmpty));
|
||||
|
||||
parent.addTest("UtilityTest", &suite);
|
||||
}
|
||||
@@ -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 <TestCase.h>
|
||||
#include <TestSuite.h>
|
||||
|
||||
|
||||
class UtilityTest : public CppUnit::TestCase {
|
||||
public:
|
||||
UtilityTest();
|
||||
virtual ~UtilityTest();
|
||||
|
||||
void TestTranslatePath();
|
||||
|
||||
static void AddTests(BTestSuite& suite);
|
||||
};
|
||||
|
||||
|
||||
#endif // UTILITY_TEST_H
|
||||
Reference in New Issue
Block a user