Optionally ignore EACCES in realpath.
GitOrigin-RevId: 8043b753ec748b6ff21accb5efde782047e5cd50
This commit is contained in:
parent
a40619aa64
commit
55b16026c5
@ -4374,7 +4374,7 @@ Status Td::fix_parameters(TdParameters ¶meters) {
|
||||
dir += TD_DIR_SLASH;
|
||||
}
|
||||
TRY_STATUS(mkpath(dir, 0750));
|
||||
TRY_RESULT(real_dir, realpath(dir));
|
||||
TRY_RESULT(real_dir, realpath(dir, true));
|
||||
if (dir.back() != TD_DIR_SLASH) {
|
||||
dir += TD_DIR_SLASH;
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64
|
||||
if (location.path_.empty()) {
|
||||
return Status::Error("File must have non-empty path");
|
||||
}
|
||||
TRY_RESULT(path, realpath(location.path_));
|
||||
TRY_RESULT(path, realpath(location.path_, true));
|
||||
if (bad_paths_.count(path) != 0) {
|
||||
return Status::Error("Sending of internal database files is forbidden");
|
||||
}
|
||||
|
@ -719,7 +719,7 @@ Status HttpReader::open_temp_file(CSlice desired_file_name) {
|
||||
return Status::Error("Can't find temporary directory");
|
||||
}
|
||||
|
||||
TRY_RESULT(dir, realpath(tmp_dir));
|
||||
TRY_RESULT(dir, realpath(tmp_dir, true));
|
||||
CHECK(!dir.empty());
|
||||
|
||||
auto first_try = try_open_temp_file(dir, desired_file_name);
|
||||
|
@ -81,13 +81,19 @@ Status rename(CSlice from, CSlice to) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Result<string> realpath(CSlice slice) {
|
||||
Result<string> realpath(CSlice slice, bool ignore_access_denied) {
|
||||
char full_path[PATH_MAX + 1];
|
||||
string res;
|
||||
char *err = skip_eintr([&] { return ::realpath(slice.c_str(), full_path); });
|
||||
if (err != full_path) {
|
||||
return OS_ERROR(PSLICE() << "Realpath failed for \"" << slice << '"');
|
||||
if (ignore_access_denied && errno == EACCES) {
|
||||
res = slice.str();
|
||||
} else {
|
||||
return OS_ERROR(PSLICE() << "Realpath failed for \"" << slice << '"');
|
||||
}
|
||||
} else {
|
||||
res = full_path;
|
||||
}
|
||||
string res = full_path;
|
||||
if (res.empty()) {
|
||||
return Status::Error("Empty path");
|
||||
}
|
||||
@ -225,7 +231,7 @@ Status rename(CSlice from, CSlice to) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Result<string> realpath(CSlice slice) {
|
||||
Result<string> realpath(CSlice slice, bool /*ignore_access_denied*/) {
|
||||
wchar_t buf[MAX_PATH + 1];
|
||||
TRY_RESULT(wslice, to_wstring(slice));
|
||||
auto status = GetFullPathNameW(wslice.c_str(), MAX_PATH, buf, nullptr);
|
||||
|
@ -38,7 +38,7 @@ namespace td {
|
||||
Status mkdir(CSlice dir, int32 mode = 0700) TD_WARN_UNUSED_RESULT;
|
||||
Status mkpath(CSlice path, int32 mode = 0700) TD_WARN_UNUSED_RESULT;
|
||||
Status rename(CSlice from, CSlice to) TD_WARN_UNUSED_RESULT;
|
||||
Result<string> realpath(CSlice slice) TD_WARN_UNUSED_RESULT;
|
||||
Result<string> realpath(CSlice slice, bool ignore_access_denied = false) TD_WARN_UNUSED_RESULT;
|
||||
Status chdir(CSlice dir) TD_WARN_UNUSED_RESULT;
|
||||
Status rmdir(CSlice dir) TD_WARN_UNUSED_RESULT;
|
||||
Status unlink(CSlice path) TD_WARN_UNUSED_RESULT;
|
||||
|
Loading…
Reference in New Issue
Block a user