2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
19 #include <sys/types.h>
20 #include <sys/mount.h>
22 #include "krate-builder.h"
24 #include <klay/exception.h>
25 #include <klay/filesystem.h>
27 KrateBuilder::KrateBuilder(const runtime::User& user, const std::string& manifestPath) :
28 name(user.getName()), uid(user.getUid()), gid(user.getGid())
30 runtime::File data(manifestPath);
32 manifest.reset(xml::Parser::parseFile(manifestPath));
36 KrateBuilder::~KrateBuilder()
40 void KrateBuilder::bindFilesystemNode(const std::string& source, const std::string& target,
41 const std::string& type, const std::string& options,
45 runtime::File dir(target);
47 dir.makeDirectory(true, uid, gid);
51 runtime::Mount::mountEntry(source, target, type, options);
54 void KrateBuilder::mountOwnFilesystem()
57 xml::Node::NodeList entries = manifest->evaluate("/manifest/filesystem/entry");
58 for (const xml::Node& entry : entries) {
59 bindFilesystemNode(entry.getProp("source"), entry.getProp("target"),
60 entry.getProp("type"), entry.getProp("options"));
64 bindFilesystemNode("/home/" + name,
65 "/home/" + name + "/.krate/" + name,
68 bindFilesystemNode("/home/" + name + "/.krate", "/home",