Terrasync: Fix exception deleting orphaned directories.
This commit is contained in:
@@ -142,7 +142,7 @@ public:
|
|||||||
void finishedRequest(const RepoRequestPtr& req);
|
void finishedRequest(const RepoRequestPtr& req);
|
||||||
|
|
||||||
HTTPDirectory* getOrCreateDirectory(const std::string& path);
|
HTTPDirectory* getOrCreateDirectory(const std::string& path);
|
||||||
bool deleteDirectory(const std::string& path);
|
bool deleteDirectory(const std::string& relPath, const SGPath& absPath);
|
||||||
|
|
||||||
typedef std::vector<HTTPDirectory*> DirectoryVector;
|
typedef std::vector<HTTPDirectory*> DirectoryVector;
|
||||||
DirectoryVector directories;
|
DirectoryVector directories;
|
||||||
@@ -317,7 +317,8 @@ public:
|
|||||||
ChildInfoList::iterator c = findIndexChild(it->file());
|
ChildInfoList::iterator c = findIndexChild(it->file());
|
||||||
if (c == children.end()) {
|
if (c == children.end()) {
|
||||||
SG_LOG(SG_TERRASYNC, SG_DEBUG, "is orphan '" << it->file() << "'" );
|
SG_LOG(SG_TERRASYNC, SG_DEBUG, "is orphan '" << it->file() << "'" );
|
||||||
orphans.push_back(it->file());
|
|
||||||
|
orphans.push_back(it->file());
|
||||||
} else if (c->hash != hash) {
|
} else if (c->hash != hash) {
|
||||||
SG_LOG(SG_TERRASYNC, SG_DEBUG, "hash mismatch'" << it->file() );
|
SG_LOG(SG_TERRASYNC, SG_DEBUG, "hash mismatch'" << it->file() );
|
||||||
// file exists, but hash mismatch, schedule update
|
// file exists, but hash mismatch, schedule update
|
||||||
@@ -534,7 +535,7 @@ private:
|
|||||||
|
|
||||||
std::string fpath = _relativePath + "/" + name;
|
std::string fpath = _relativePath + "/" + name;
|
||||||
if (p.isDir()) {
|
if (p.isDir()) {
|
||||||
ok = _repository->deleteDirectory(fpath);
|
ok = _repository->deleteDirectory(fpath, p);
|
||||||
} else {
|
} else {
|
||||||
// remove the hash cache entry
|
// remove the hash cache entry
|
||||||
_repository->updatedFileContents(p, std::string());
|
_repository->updatedFileContents(p, std::string());
|
||||||
@@ -1044,25 +1045,26 @@ HTTPRepository::failure() const
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTPRepoPrivate::deleteDirectory(const std::string& path)
|
bool HTTPRepoPrivate::deleteDirectory(const std::string& relPath, const SGPath& absPath)
|
||||||
{
|
{
|
||||||
DirectoryWithPath p(path);
|
DirectoryWithPath p(relPath);
|
||||||
DirectoryVector::iterator it = std::find_if(directories.begin(), directories.end(), p);
|
auto it = std::find_if(directories.begin(), directories.end(), p);
|
||||||
if (it != directories.end()) {
|
if (it != directories.end()) {
|
||||||
HTTPDirectory* d = *it;
|
HTTPDirectory* d = *it;
|
||||||
|
assert(d->absolutePath() == absPath);
|
||||||
directories.erase(it);
|
directories.erase(it);
|
||||||
Dir dir(d->absolutePath());
|
|
||||||
bool result = dir.remove(true);
|
|
||||||
|
|
||||||
// update the hash cache too
|
|
||||||
updatedFileContents(d->absolutePath(), std::string());
|
|
||||||
|
|
||||||
delete d;
|
delete d;
|
||||||
|
} else {
|
||||||
|
// we encounter this code path when deleting an orphaned directory
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
Dir dir(absPath);
|
||||||
}
|
bool result = dir.remove(true);
|
||||||
|
|
||||||
return false;
|
// update the hash cache too
|
||||||
|
updatedFileContents(absPath, std::string());
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPRepoPrivate::makeRequest(RepoRequestPtr req)
|
void HTTPRepoPrivate::makeRequest(RepoRequestPtr req)
|
||||||
|
|||||||
Reference in New Issue
Block a user