Create a symlink instead of copying the file when deployFile is requested with source and target paths inside the AppDir

This commit is contained in:
Alexis Lopez Zubieta
2018-11-02 21:24:20 -06:00
parent 83a9690da1
commit b86ccd46ee
2 changed files with 28 additions and 2 deletions
+23
View File
@@ -6,10 +6,33 @@
#include <sstream>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
namespace linuxdeploy {
namespace util {
namespace misc {
static bool path_contains_file(boost::filesystem::path dir, boost::filesystem::path file) {
// If dir ends with "/" and isn't the root directory, then the final
// component returned by iterators will include "." and will interfere
// with the std::equal check below, so we strip it before proceeding.
if (dir.filename() == ".")
dir.remove_filename();
// We're also not interested in the file's name.
assert(file.has_filename());
file.remove_filename();
// If dir has more components than file, then file can't possibly
// reside in dir.
auto dir_len = std::distance(dir.begin(), dir.end());
auto file_len = std::distance(file.begin(), file.end());
if (dir_len > file_len)
return false;
// This stops checking when it reaches dir.end(), so it's OK if file
// has more directory components afterward. They won't be checked.
return std::equal(dir.begin(), dir.end(), file.begin());
};
static inline bool ltrim(std::string& s, char to_trim = ' ') {
// TODO: find more efficient way to check whether elements have been removed
size_t initialLength = s.length();
+5 -2
View File
@@ -20,6 +20,7 @@
#include "excludelist.h"
using namespace linuxdeploy::core;
using namespace linuxdeploy::util::misc;
using namespace linuxdeploy::core::log;
using namespace cimg_library;
@@ -159,8 +160,10 @@ namespace linuxdeploy {
const auto& from = pair.first;
const auto& to = pair.second;
if (!copyFile(from, to))
success = false;
if (path_contains_file(appDirPath, from)) {
success = bf::exists(to) || symlinkFile(from, to, true); // create a symbolic link
} else
success = copyFile(from, to); // copy the file
copyOperations.erase(copyOperations.begin());
}