launch_daemon: "file_exists" now resolves $HOME, and '~'.

This commit is contained in:
Axel Dörfler
2015-10-19 21:22:21 +02:00
parent 4e8fc45146
commit d9bb9513c5
9 changed files with 106 additions and 5 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ target desktop {
} }
job user-bootscript { job user-bootscript {
launch /bin/sh /boot/home/config/settings/boot/UserBootscript launch /bin/sh ~/config/settings/boot/UserBootscript
} }
job create-installer-link { job create-installer-link {
@@ -26,7 +26,7 @@ target desktop {
read_only read_only
file_exists /boot/system/apps/Installer 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
} }
} }
+1 -1
View File
@@ -413,7 +413,7 @@ FileExistsCondition::FileExistsCondition(const BMessage& args)
{ {
for (int32 index = 0; for (int32 index = 0;
const char* path = args.GetString("args", index, NULL); index++) { const char* path = args.GetString("args", index, NULL); index++) {
fPaths.Add(path); fPaths.Add(Utility::TranslatePath(path));
} }
} }
+1 -1
View File
@@ -975,7 +975,7 @@ LaunchDaemon::_AddJob(Target* target, bool service, BMessage& message)
const char* argument; const char* argument;
for (int32 index = 0; message.FindString("launch", index, &argument) for (int32 index = 0; message.FindString("launch", index, &argument)
== B_OK; index++) { == B_OK; index++) {
job->AddArgument(argument); job->AddArgument(Utility::TranslatePath(argument));
} }
} }
+16
View File
@@ -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 } // namespace Utility
+3 -1
View File
@@ -6,7 +6,7 @@
#define UTILITY_H #define UTILITY_H
#include <SupportDefs.h> #include <String.h>
namespace Utility { namespace Utility {
@@ -15,6 +15,8 @@ namespace Utility {
status_t BlockMedia(const char* path, bool block); status_t BlockMedia(const char* path, bool block);
status_t EjectMedia(const char* path); status_t EjectMedia(const char* path);
BString TranslatePath(const char* path);
} }
+1
View File
@@ -11,6 +11,7 @@ UnitTestLib liblaunch_daemontest.so :
SettingsParserTest.cpp SettingsParserTest.cpp
ConditionsTest.cpp ConditionsTest.cpp
UtilityTest.cpp
# from the launch_daemon # from the launch_daemon
SettingsParser.cpp SettingsParser.cpp
@@ -9,6 +9,7 @@
#include "ConditionsTest.h" #include "ConditionsTest.h"
#include "SettingsParserTest.h" #include "SettingsParserTest.h"
#include "UtilityTest.h"
BTestSuite* BTestSuite*
@@ -18,6 +19,7 @@ getTestSuite()
SettingsParserTest::AddTests(*suite); SettingsParserTest::AddTests(*suite);
ConditionsTest::AddTests(*suite); ConditionsTest::AddTests(*suite);
UtilityTest::AddTests(*suite);
return suite; return suite;
} }
+56
View File
@@ -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);
}
+24
View File
@@ -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