mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-22 21:34:32 -04:00
fixed bug in removal of directory
This commit is contained in:
parent
4b00d47d3a
commit
6a30e44756
2 changed files with 25 additions and 3 deletions
|
@ -141,7 +141,7 @@ public:
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool removeDirectory(const DirectoryStorage::EntryIndex& indx)
|
bool removeDirectory(DirectoryStorage::EntryIndex indx) // no reference here! Very important. Otherwise, the messign we do inside can change the value of indx!!
|
||||||
{
|
{
|
||||||
// check that it's a directory
|
// check that it's a directory
|
||||||
|
|
||||||
|
@ -151,6 +151,10 @@ public:
|
||||||
if(indx == 0)
|
if(indx == 0)
|
||||||
return nodeAccessError("checkIndex(): Cannot remove top level directory") ;
|
return nodeAccessError("checkIndex(): Cannot remove top level directory") ;
|
||||||
|
|
||||||
|
#ifdef DEBUG_DIRECTORY_STORAGE
|
||||||
|
std::cerr << "(--) Removing directory " << indx << std::endl;
|
||||||
|
print();
|
||||||
|
#endif
|
||||||
// remove from parent
|
// remove from parent
|
||||||
|
|
||||||
DirEntry& d(*static_cast<DirEntry*>(mNodes[indx])) ;
|
DirEntry& d(*static_cast<DirEntry*>(mNodes[indx])) ;
|
||||||
|
@ -158,8 +162,19 @@ public:
|
||||||
|
|
||||||
for(uint32_t i=0;i<parent_dir.subdirs.size();++i)
|
for(uint32_t i=0;i<parent_dir.subdirs.size();++i)
|
||||||
if(parent_dir.subdirs[i] == indx)
|
if(parent_dir.subdirs[i] == indx)
|
||||||
return recursRemoveDirectory(indx) ;
|
{
|
||||||
|
parent_dir.subdirs[i] = parent_dir.subdirs.back() ;
|
||||||
|
parent_dir.subdirs.pop_back();
|
||||||
|
|
||||||
|
bool res = recursRemoveDirectory(indx) ;
|
||||||
|
#ifdef DEBUG_DIRECTORY_STORAGE
|
||||||
|
print();
|
||||||
|
std::string err ;
|
||||||
|
if(!check(err))
|
||||||
|
std::cerr << "(EE) Error after removing subdirectory. Error string=\"" << err << "\", Hierarchy is : " << std::endl;
|
||||||
|
#endif
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
return nodeAccessError("removeDirectory(): inconsistency!!") ;
|
return nodeAccessError("removeDirectory(): inconsistency!!") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +510,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i=0;i<hits.size();++i)
|
for(uint32_t i=0;i<hits.size();++i)
|
||||||
if(hits[i] == 0)
|
if(hits[i] == 0 && mNodes[i] != NULL)
|
||||||
{
|
{
|
||||||
error_string = "Orphean node!" ;
|
error_string = "Orphean node!" ;
|
||||||
return false;
|
return false;
|
||||||
|
@ -581,6 +596,11 @@ private:
|
||||||
for(uint32_t i=0;i<d.subdirs.size();++i)
|
for(uint32_t i=0;i<d.subdirs.size();++i)
|
||||||
recursRemoveDirectory(d.subdirs[i]);
|
recursRemoveDirectory(d.subdirs[i]);
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<d.subfiles.size();++i)
|
||||||
|
{
|
||||||
|
delete mNodes[d.subfiles[i]] ;
|
||||||
|
mNodes[d.subfiles[i]] = NULL ;
|
||||||
|
}
|
||||||
delete mNodes[dir] ;
|
delete mNodes[dir] ;
|
||||||
mNodes[dir] = NULL ;
|
mNodes[dir] = NULL ;
|
||||||
|
|
||||||
|
|
|
@ -840,6 +840,8 @@ void p3FileDatabase::handleDirSyncResponse(RsFileListsSyncResponseItem *item)
|
||||||
{
|
{
|
||||||
P3FILELISTS_DEBUG() << " removing directory with index " << item->entry_index << " because it does not exist." << std::endl;
|
P3FILELISTS_DEBUG() << " removing directory with index " << item->entry_index << " because it does not exist." << std::endl;
|
||||||
mRemoteDirectories[fi]->removeDirectory(item->entry_index);
|
mRemoteDirectories[fi]->removeDirectory(item->entry_index);
|
||||||
|
|
||||||
|
mRemoteDirectories[fi]->print();
|
||||||
}
|
}
|
||||||
else if(item->flags & RsFileListsItem::FLAGS_ENTRY_UP_TO_DATE)
|
else if(item->flags & RsFileListsItem::FLAGS_ENTRY_UP_TO_DATE)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue