From 494d2071c95a4290a91ce6fc2efdc933b9593667 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sun, 28 Aug 2016 18:42:52 +0200 Subject: [PATCH] fixed update of directory TS, also fixing update of empty dirs at friends --- .../src/file_sharing/directory_storage.cc | 48 +++++++++++++------ .../src/file_sharing/directory_storage.h | 2 +- .../src/file_sharing/directory_updater.cc | 10 ++-- libretroshare/src/file_sharing/p3filelists.cc | 9 +--- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 20a093b2f..e801b4ba8 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -47,10 +47,10 @@ public: virtual ~FileEntry() {} // local stuff + time_t file_modtime; std::string file_name ; uint64_t file_size ; RsFileHash file_hash ; - time_t file_modtime ; }; class DirEntry: public FileStorageNode @@ -68,18 +68,21 @@ public: std::vector subdirs ; std::vector subfiles ; - time_t dir_modtime ; // this accounts for deleted files, etc. + time_t dir_modtime; time_t most_recent_time; // recursive most recent modification time, including files and subdirs in the entire hierarchy below. - time_t dir_update_time; // last time the information was updated for that directory. Includes subdirs indexes and subfile info. }; // class stuff InternalFileHierarchyStorage() : mRoot(0) { - mNodes.push_back(new DirEntry("")) ; - mNodes.back()->row=0; - mNodes.back()->parent_index=0; + DirEntry *de = new DirEntry("") ; + + de->row=0; + de->parent_index=0; + de->dir_modtime=0; + + mNodes.push_back(de) ; } int parentRow(DirectoryStorage::EntryIndex e) @@ -97,14 +100,14 @@ public: return e < mNodes.size() && mNodes[e] != NULL ; } - bool updateSubDirectoryList(const DirectoryStorage::EntryIndex& indx,const std::set& subdirs) + bool updateSubDirectoryList(const DirectoryStorage::EntryIndex& indx,const std::map& subdirs) { if(!checkIndex(indx,FileStorageNode::TYPE_DIR)) return false; DirEntry& d(*static_cast(mNodes[indx])) ; - std::set should_create(subdirs); + std::map should_create(subdirs); for(uint32_t i=0;i(mNodes[d.subdirs[i]])->dir_name) == subdirs.end()) @@ -122,14 +125,18 @@ public: ++i; } - for(std::set::const_iterator it(should_create.begin());it!=should_create.end();++it) + for(std::map::const_iterator it(should_create.begin());it!=should_create.end();++it) { - std::cerr << "[directory storage] adding new subdirectory " << *it << " at index " << mNodes.size() << std::endl; + std::cerr << "[directory storage] adding new subdirectory " << it->first << " at index " << mNodes.size() << std::endl; + + DirEntry *de = new DirEntry(it->first) ; + + de->row = mNodes.size(); + de->parent_index = indx; + de->dir_modtime = it->second; d.subdirs.push_back(mNodes.size()) ; - mNodes.push_back(new DirEntry(*it)); - mNodes.back()->row = mNodes.size()-1; - mNodes.back()->parent_index = indx; + mNodes.push_back(de) ; } return true; @@ -664,7 +671,7 @@ bool DirectoryStorage::setDirUpdateTS(EntryIndex index,time_t recurs_max_modf_T return mFileHierarchy->setDirUpdateTS(index,recurs_max_modf_TS,local_update_TS) ; } -bool DirectoryStorage::updateSubDirectoryList(const EntryIndex& indx,const std::set& subdirs) +bool DirectoryStorage::updateSubDirectoryList(const EntryIndex& indx,const std::map& subdirs) { RS_STACK_MUTEX(mDirStorageMtx) ; bool res = mFileHierarchy->updateSubDirectoryList(indx,subdirs) ; @@ -1035,6 +1042,10 @@ bool RemoteDirectoryStorage::deserialiseDirEntry(const EntryIndex& indx,const Rs if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_RECURS_MODIF_TS,most_recent_time)) return false ; if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_MODIF_TS ,dir_modtime )) return false ; + std::cerr << " dir name : \"" << dir_name << "\"" << std::endl; + std::cerr << " most recent time : " << most_recent_time << std::endl; + std::cerr << " modification time : " << dir_modtime << std::endl; + // serialise number of subdirs and number of subfiles uint32_t n_subdirs,n_subfiles ; @@ -1042,6 +1053,9 @@ bool RemoteDirectoryStorage::deserialiseDirEntry(const EntryIndex& indx,const Rs if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_RAW_NUMBER,n_subdirs )) return false ; if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_RAW_NUMBER,n_subfiles )) return false ; + std::cerr << " number of subdirs : " << n_subdirs << std::endl; + std::cerr << " number of files : " << n_subfiles << std::endl; + // serialise subdirs entry indexes std::vector subdirs_array ; @@ -1095,6 +1109,8 @@ bool RemoteDirectoryStorage::deserialiseDirEntry(const EntryIndex& indx,const Rs RS_STACK_MUTEX(mDirStorageMtx) ; + std::cerr << " updating dir entry..." << std::endl; + // first create the entries for each subdir and each subfile. if(!mFileHierarchy->updateDirEntry(indx,dir_name,most_recent_time,dir_modtime,subdirs_array,subfiles_array)) { @@ -1104,8 +1120,12 @@ bool RemoteDirectoryStorage::deserialiseDirEntry(const EntryIndex& indx,const Rs // then update the subfiles for(uint32_t i=0;iupdateFile(subfiles_array[i],subfiles_hash[i],subfiles_name[i],subfiles_size[i],subfiles_modtime[i])) std::cerr << "(EE) Cannot update file with index " << subfiles_array[i] << ". This is very weird. Entry should have just been created and therefore should exist. Skipping." << std::endl; + } return true ; } diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index dd3353ad1..c86477d19 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -94,7 +94,7 @@ class DirectoryStorage const RsPeerId& peerId() const { return mPeerId ; } int parentRow(EntryIndex e) const ; - bool updateSubDirectoryList(const EntryIndex& indx,const std::set& subdirs) ; + bool updateSubDirectoryList(const EntryIndex& indx, const std::map &subdirs) ; bool updateSubFilesList(const EntryIndex& indx, const std::map &subfiles, std::map &new_files) ; bool removeDirectory(const EntryIndex& indx) ; diff --git a/libretroshare/src/file_sharing/directory_updater.cc b/libretroshare/src/file_sharing/directory_updater.cc index f9fada262..2af4c036f 100644 --- a/libretroshare/src/file_sharing/directory_updater.cc +++ b/libretroshare/src/file_sharing/directory_updater.cc @@ -59,10 +59,10 @@ void LocalDirectoryUpdater::sweepSharedDirectories() std::list shared_directory_list ; mSharedDirectories->getSharedDirectoryList(shared_directory_list); - std::set sub_dir_list ; + std::map sub_dir_list ; for(std::list::const_iterator real_dir_it(shared_directory_list.begin());real_dir_it!=shared_directory_list.end();++real_dir_it) - sub_dir_list.insert( (*real_dir_it).filename ) ; + sub_dir_list[(*real_dir_it).filename] = 0 ; // make sure that entries in stored_dir_it are the same than paths in real_dir_it, and in the same order. @@ -93,7 +93,7 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p // collect subdirs and subfiles std::map subfiles ; - std::set subdirs ; + std::map subdirs ; for(;dirIt.isValid();dirIt.next()) { @@ -104,7 +104,7 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p std::cerr << " adding sub-file \"" << dirIt.file_name() << "\"" << std::endl; break; - case librs::util::FolderIterator::TYPE_DIR: subdirs.insert(dirIt.file_name()) ; + case librs::util::FolderIterator::TYPE_DIR: subdirs[dirIt.file_name()] = dirIt.file_modtime(); std::cerr << " adding sub-dir \"" << dirIt.file_name() << "\"" << std::endl; break; default: @@ -134,7 +134,7 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p DirectoryStorage::DirIterator stored_dir_it(mSharedDirectories,indx) ; - for(std::set::const_iterator real_dir_it(subdirs.begin());real_dir_it!=subdirs.end();++real_dir_it, ++stored_dir_it) + for(std::map::const_iterator real_dir_it(subdirs.begin());real_dir_it!=subdirs.end();++real_dir_it, ++stored_dir_it) { std::cerr << " recursing into " << stored_dir_it.name() << std::endl; recursUpdateSharedDir(cumulated_path + "/" + stored_dir_it.name(), *stored_dir_it) ; diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 403233183..ea6fce421 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -834,15 +834,10 @@ void p3FileDatabase::handleDirSyncResponse(RsFileListsSyncResponseItem *item) } else if(item->flags & RsFileListsItem::FLAGS_SYNC_DIR_CONTENT) { - P3FILELISTS_DEBUG() << " Item contains directory data. Updating." << std::endl; + P3FILELISTS_DEBUG() << " Item contains directory data. Deserialising/Updating." << std::endl; if(mRemoteDirectories[fi]->deserialiseDirEntry(item->entry_index,item->directory_content_data)) - { - mRemoteDirectories[fi]->setDirUpdateTS(item->entry_index,item->last_known_recurs_modf_TS,time(NULL)); - - // notify the GUI if the hierarchy has changed - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); - } + RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); // notify the GUI if the hierarchy has changed else std::cerr << "(EE) Cannot deserialise dir entry. ERROR. "<< std::endl;