mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 12:50:00 +00:00
Add an optional 'bool makeAbsolute' in llvm::sys::fs::unique_file function.
If true and 'model' parameter is not an absolute path, a temp directory will be prepended. Make it true by default to match current behaviour. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136310 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7b2958392c
commit
814450a429
@ -427,10 +427,13 @@ error_code symlink_status(const Twine &path, file_status &result);
|
||||
/// @param model Name to base unique path off of.
|
||||
/// @param result_fs Set to the opened file's file descriptor.
|
||||
/// @param result_path Set to the opened file's absolute path.
|
||||
/// @param makeAbsolute If true and @model is not an absolute path, a temp
|
||||
/// directory will be prepended.
|
||||
/// @results errc::success if result_{fd,path} have been successfully set,
|
||||
/// otherwise a platform specific error_code.
|
||||
error_code unique_file(const Twine &model, int &result_fd,
|
||||
SmallVectorImpl<char> &result_path);
|
||||
SmallVectorImpl<char> &result_path,
|
||||
bool makeAbsolute = true);
|
||||
|
||||
/// @brief Canonicalize path.
|
||||
///
|
||||
|
@ -342,19 +342,22 @@ error_code status(const Twine &path, file_status &result) {
|
||||
}
|
||||
|
||||
error_code unique_file(const Twine &model, int &result_fd,
|
||||
SmallVectorImpl<char> &result_path) {
|
||||
SmallVectorImpl<char> &result_path,
|
||||
bool makeAbsolute) {
|
||||
SmallString<128> Model;
|
||||
model.toVector(Model);
|
||||
// Null terminate.
|
||||
Model.c_str();
|
||||
|
||||
// Make model absolute by prepending a temp directory if it's not already.
|
||||
bool absolute = path::is_absolute(Twine(Model));
|
||||
if (!absolute) {
|
||||
SmallString<128> TDir;
|
||||
if (error_code ec = TempDir(TDir)) return ec;
|
||||
path::append(TDir, Twine(Model));
|
||||
Model.swap(TDir);
|
||||
if (makeAbsolute) {
|
||||
// Make model absolute by prepending a temp directory if it's not already.
|
||||
bool absolute = path::is_absolute(Twine(Model));
|
||||
if (!absolute) {
|
||||
SmallString<128> TDir;
|
||||
if (error_code ec = TempDir(TDir)) return ec;
|
||||
path::append(TDir, Twine(Model));
|
||||
Model.swap(TDir);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace '%' with random chars. From here on, DO NOT modify model. It may be
|
||||
|
@ -501,7 +501,8 @@ handle_status_error:
|
||||
}
|
||||
|
||||
error_code unique_file(const Twine &model, int &result_fd,
|
||||
SmallVectorImpl<char> &result_path) {
|
||||
SmallVectorImpl<char> &result_path,
|
||||
bool makeAbsolute) {
|
||||
// Use result_path as temp storage.
|
||||
result_path.set_size(0);
|
||||
StringRef m = model.toStringRef(result_path);
|
||||
@ -509,17 +510,19 @@ error_code unique_file(const Twine &model, int &result_fd,
|
||||
SmallVector<wchar_t, 128> model_utf16;
|
||||
if (error_code ec = UTF8ToUTF16(m, model_utf16)) return ec;
|
||||
|
||||
// Make model absolute by prepending a temp directory if it's not already.
|
||||
bool absolute = path::is_absolute(m);
|
||||
|
||||
if (!absolute) {
|
||||
SmallVector<wchar_t, 64> temp_dir;
|
||||
if (error_code ec = TempDir(temp_dir)) return ec;
|
||||
// Handle c: by removing it.
|
||||
if (model_utf16.size() > 2 && model_utf16[1] == L':') {
|
||||
model_utf16.erase(model_utf16.begin(), model_utf16.begin() + 2);
|
||||
if (makeAbsolute) {
|
||||
// Make model absolute by prepending a temp directory if it's not already.
|
||||
bool absolute = path::is_absolute(m);
|
||||
|
||||
if (!absolute) {
|
||||
SmallVector<wchar_t, 64> temp_dir;
|
||||
if (error_code ec = TempDir(temp_dir)) return ec;
|
||||
// Handle c: by removing it.
|
||||
if (model_utf16.size() > 2 && model_utf16[1] == L':') {
|
||||
model_utf16.erase(model_utf16.begin(), model_utf16.begin() + 2);
|
||||
}
|
||||
model_utf16.insert(model_utf16.begin(), temp_dir.begin(), temp_dir.end());
|
||||
}
|
||||
model_utf16.insert(model_utf16.begin(), temp_dir.begin(), temp_dir.end());
|
||||
}
|
||||
|
||||
// Replace '%' with random chars. From here on, DO NOT modify model. It may be
|
||||
|
Loading…
Reference in New Issue
Block a user