mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
Support/FileSystem: Add create_director{y,ies} implementations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120790 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -671,6 +671,21 @@ error_code is_relative(const Twine &path, bool &result) {
|
|||||||
|
|
||||||
namespace fs {
|
namespace fs {
|
||||||
|
|
||||||
|
error_code create_directories(const Twine &path, bool &existed) {
|
||||||
|
SmallString<128> path_storage;
|
||||||
|
StringRef p = path.toStringRef(path_storage);
|
||||||
|
|
||||||
|
StringRef parent;
|
||||||
|
bool parent_exists;
|
||||||
|
if (error_code ec = path::parent_path(p, parent)) return ec;
|
||||||
|
if (error_code ec = fs::exists(parent, parent_exists)) return ec;
|
||||||
|
|
||||||
|
if (!parent_exists)
|
||||||
|
return create_directories(parent, existed);
|
||||||
|
|
||||||
|
return create_directory(p, existed);
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace fs
|
} // end namespace fs
|
||||||
} // end namespace sys
|
} // end namespace sys
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
@@ -146,6 +146,20 @@ error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
|
|||||||
return make_error_code(errc::success);
|
return make_error_code(errc::success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code create_directory(const Twine &path, bool &existed) {
|
||||||
|
SmallString<128> path_storage;
|
||||||
|
StringRef p = path.toNullTerminatedStringRef(path_storage);
|
||||||
|
|
||||||
|
if (::mkdir(p.begin(), 0700) == -1) {
|
||||||
|
if (errno != EEXIST)
|
||||||
|
return error_code(errno, system_category());
|
||||||
|
existed = true;
|
||||||
|
} else
|
||||||
|
existed = false;
|
||||||
|
|
||||||
|
return make_error_code(errc::success);
|
||||||
|
}
|
||||||
|
|
||||||
error_code exists(const Twine &path, bool &result) {
|
error_code exists(const Twine &path, bool &result) {
|
||||||
SmallString<128> path_storage;
|
SmallString<128> path_storage;
|
||||||
StringRef p = path.toNullTerminatedStringRef(path_storage);
|
StringRef p = path.toNullTerminatedStringRef(path_storage);
|
||||||
|
@@ -181,6 +181,26 @@ error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
|
|||||||
return make_error_code(errc::success);
|
return make_error_code(errc::success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code create_directory(const Twine &path, bool &existed) {
|
||||||
|
SmallString<128> path_storage;
|
||||||
|
SmallVector<wchar_t, 128> path_utf16;
|
||||||
|
|
||||||
|
if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
|
||||||
|
path_utf16))
|
||||||
|
return ec;
|
||||||
|
|
||||||
|
if (!::CreateDirectoryW(path_utf16.begin(), NULL)) {
|
||||||
|
error_code ec = make_error_code(windows_error(::GetLastError()));
|
||||||
|
if (ec == make_error_code(windows_error::already_exists))
|
||||||
|
existed = true;
|
||||||
|
else
|
||||||
|
return ec;
|
||||||
|
} else
|
||||||
|
existed = false;
|
||||||
|
|
||||||
|
return make_error_code(errc::success);
|
||||||
|
}
|
||||||
|
|
||||||
error_code exists(const Twine &path, bool &result) {
|
error_code exists(const Twine &path, bool &result) {
|
||||||
SmallString<128> path_storage;
|
SmallString<128> path_storage;
|
||||||
SmallVector<wchar_t, 128> path_utf16;
|
SmallVector<wchar_t, 128> path_utf16;
|
||||||
|
Reference in New Issue
Block a user