feat: support copy-symlink

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2024-05-08 18:09:15 +08:00 committed by Comix
parent b4cb15dfc8
commit 54dd0f4f0c
5 changed files with 33 additions and 4 deletions

View File

@ -448,7 +448,9 @@ public:
{
if (runtime.mounts.has_value()) {
for (auto const &mount : runtime.mounts.value()) {
containerMounter->MountNode(mount);
if (containerMounter->MountNode(mount) != 0) {
logWan() << "failed to Mount:" << strerror(errno);
}
}
};

View File

@ -10,6 +10,8 @@
#include "util/debug/debug.h"
#include "util/logger.h"
#include <linux/limits.h>
#include <utility>
#include <sys/stat.h>
@ -72,6 +74,17 @@ public:
}
case S_IFLNK: {
driver_->CreateDestinationPath(dest_parent_path);
if (m.extraFlags & OPTION_COPY_SYMLINK) {
std::array<char, PATH_MAX + 1> buf{};
buf.fill(0);
auto len = readlink(source.c_str(), buf._M_elems, PATH_MAX);
if (len == -1) {
logErr() << "readlink failed:" << source << strerror(errno);
return -1;
}
return host_dest_full_path.touch_symlink(std::string(buf.cbegin(), buf.cend()));
}
host_dest_full_path.touch();
source = util::fs::read_symlink(util::fs::path(source)).string();
break;
@ -198,7 +211,7 @@ public:
<< "failed:" << util::RetErrString(ret) << "\nmount args is:" << m.type
<< real_flags << real_data;
if (is_path) {
logErr() << "source file type is: 0x" << std::hex << (source_stat.st_mode & S_IFMT);
logErr() << "source file type is: 0x" << std::oct << (source_stat.st_mode & S_IFMT);
DUMP_FILE_INFO(source);
}
DUMP_FILE_INFO(host_dest_full_path.string());

View File

@ -86,6 +86,11 @@ public:
}
}
int touch_symlink(const std::string &target) const
{
return symlink(target.c_str(), this->string().c_str());
}
private:
friend std::ostream &operator<<(std::ostream &cout, path obj);
std::vector<std::string> p;

View File

@ -86,8 +86,11 @@ struct Mount
Type fsType;
uint32_t flags = 0u;
uint32_t extraFlags{ 0U };
};
enum { OPTION_COPY_SYMLINK = 1 };
inline void from_json(const nlohmann::json &j, Mount &o)
{
static std::map<std::string, Mount::Type> fsTypes = {
@ -100,6 +103,7 @@ inline void from_json(const nlohmann::json &j, Mount &o)
{
bool clear;
uint32_t flag;
uint32_t extraFlags{ 0 };
};
static std::map<std::string, mountFlag> optionFlags = {
@ -138,6 +142,7 @@ inline void from_json(const nlohmann::json &j, Mount &o)
{ "suid", { true, MS_NOSUID } },
{ "sync", { false, MS_SYNCHRONOUS } },
// {"symfollow",{true, MS_NOSYMFOLLOW}}, // since kernel 5.10
{ "copy-symlink", { false, 0, OPTION_COPY_SYMLINK } }
};
o.destination = j.at("destination").get<std::string>();
@ -158,8 +163,12 @@ inline void from_json(const nlohmann::json &j, Mount &o)
if (it != optionFlags.end()) {
if (it->second.clear) {
o.flags &= ~it->second.flag;
} else
o.extraFlags &= ~it->second.extraFlags;
} else {
o.flags |= it->second.flag;
o.extraFlags |= it->second.extraFlags;
}
} else {
o.data.push_back(opt);
}

View File

@ -32,7 +32,7 @@ Container::Container(const ocppi::runtime::config::types::Config &cfg,
, appID(appID)
, cli(cli)
{
Q_ASSERT(!cfg.process.has_value());
Q_ASSERT(cfg.process.has_value());
}
utils::error::Result<void>