Merge pull request #18640 from hrydgard/handle-remote-directories

Various fixes to PathBrowser etc to handle browsing HTTP subfolders
This commit is contained in:
Unknown W. Brackets 2023-12-29 13:56:10 -08:00 committed by GitHub
commit 593955a86f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 13 deletions

View file

@ -314,17 +314,16 @@ std::string Path::ToVisualString(const char *relativeRoot) const {
bool Path::CanNavigateUp() const {
if (type_ == PathType::CONTENT_URI) {
return AndroidContentURI(path_).CanNavigateUp();
}
if (path_ == "/" || path_.empty()) {
return false;
}
if (type_ == PathType::HTTP) {
} else if (type_ == PathType::HTTP) {
size_t rootSlash = path_.find_first_of('/', strlen("https://"));
if (rootSlash == path_.npos || path_.size() == rootSlash + 1) {
// This means, "http://server" or "http://server/". Can't go up.
return false;
}
}
if (path_ == "/" || path_.empty()) {
return false;
}
return true;
}

View file

@ -77,24 +77,33 @@ bool LoadRemoteFileList(const Path &url, const std::string &userAgent, bool *can
ERROR_LOG(IO, "Unsupported Content-Type: %s", contentType.c_str());
return false;
}
Path basePath(baseURL.ToString());
for (auto &item : items) {
// Apply some workarounds.
if (item.empty())
continue;
if (item.back() == '\r')
if (item.back() == '\r') {
item.pop_back();
if (item.empty())
continue;
}
if (item == baseURL.Resource())
continue;
File::FileInfo info;
if (item.back() == '/') {
item.pop_back();
if (item.empty())
continue;
info.isDirectory = true;
} else {
info.isDirectory = false;
}
info.name = item;
info.fullName = Path(baseURL.Relative(item).ToString());
info.isDirectory = endsWith(item, "/");
info.fullName = basePath / item;
info.exists = true;
info.size = 0;
info.isWritable = false;
files.push_back(info);
}

View file

@ -42,12 +42,14 @@ void Url::Split() {
size_t sep = url_.find('/', colonSlashSlash + 3);
if (sep == std::string::npos) {
valid_ = false;
return;
sep = url_.size();
}
host_ = url_.substr(colonSlashSlash + 3, sep - colonSlashSlash - 3);
resource_ = url_.substr(sep); // include the slash!
if (resource_.empty()) {
resource_ = "/"; // Assume what was meant was the root.
}
size_t portsep = host_.rfind(':');
if (portsep != host_.npos) {

View file

@ -160,8 +160,13 @@ bool RemoteISOConnectScreen::FindServer(std::string &resultHost, int &resultPort
bool supported = false;
for (const std::string &item : items) {
if (!RemoteISOFileSupported(item)) {
if (item.empty())
continue;
if (!RemoteISOFileSupported(item)) {
if (item.back() != '/') {
// We accept lists of just directories - we kinda have to.
continue;
}
}
supported = true;
break;