ソースを参照

sanitize paths

master
Martin Dørum 5年前
コミット
dd956a6dfa
4個のファイルの変更28行の追加3行の削除
  1. 4
    1
      src/CompileStep.h
  2. 21
    0
      src/sys.cc
  3. 1
    0
      src/sys.h
  4. 2
    2
      src/toolchain.cc

+ 4
- 1
src/CompileStep.h ファイルの表示



#include "DepNode.h" #include "DepNode.h"
#include "BXParser.h" #include "BXParser.h"
#include "sys.h"
#include "toolchain.h" #include "toolchain.h"


class CompileStep: public DepNode { class CompileStep: public DepNode {
std::vector<std::string> compileCommand_; std::vector<std::string> compileCommand_;
std::vector<std::string> &compileCommand(const std::string &outDir); std::vector<std::string> &compileCommand(const std::string &outDir);


std::string confPath(const std::string &outDir) { return outDir + '/' + path_ + ".bx"; }
std::string confPath(const std::string &outDir) {
return outDir + '/' + sys::sanitizePath(path_) + ".bx";
}
}; };

+ 21
- 0
src/sys.cc ファイルの表示



static thread_local std::unordered_set<std::string> mkdirp_set; static thread_local std::unordered_set<std::string> mkdirp_set;


std::string sanitizePath(const std::string &path) {
std::string npath;
size_t idx = 0;
while (idx < path.size()) {
if (idx >= path.size() - 2) {
npath += path[idx++];
} else if (path[idx] == '.' && path[idx + 1] == '.' && path[idx + 2] == '/') {
npath += "__parent__/";
idx += 3;
} else {
npath += path[idx++];
}
}

if (npath[npath.size() - 1] == '.' && npath[npath.size() - 2] == '.') {
npath.replace(npath.size() - 2, 2, "__parent__");
}

return npath;
}

FileInfo fileInfo(const std::string &path) { FileInfo fileInfo(const std::string &path) {
FileInfo finfo; FileInfo finfo;



+ 1
- 0
src/sys.h ファイルの表示

} }
}; };


std::string sanitizePath(const std::string &path);
FileInfo fileInfo(const std::string &path); FileInfo fileInfo(const std::string &path);
bool fileExists(const std::string &path); bool fileExists(const std::string &path);
void mkdirp(const std::string &path); void mkdirp(const std::string &path);

+ 2
- 2
src/toolchain.cc ファイルの表示

} }


std::string objectFilePath(const std::string &path, const std::string &outDir) { std::string objectFilePath(const std::string &path, const std::string &outDir) {
return outDir + '/' + path + ".o";
return outDir + '/' + sys::sanitizePath(path) + ".o";
} }


std::string targetFilePath( std::string targetFilePath(
TargetType type, TargetType type,
const std::string &path, const std::string &path,
const std::string &outDir) { const std::string &outDir) {
std::string base = outDir + '/' + path;
std::string base = outDir + '/' + sys::sanitizePath(path);


switch (type) { switch (type) {
case TargetType::BINARY: case TargetType::BINARY:

読み込み中…
キャンセル
保存