fixed bug in removing top dirs when creating file hierarhies

This commit is contained in:
csoler 2017-10-21 18:09:26 +02:00
parent cbcf402e0b
commit edffbc3670
3 changed files with 12 additions and 7 deletions

View File

@ -1,5 +1,6 @@
#include <iomanip> #include <iomanip>
#include <util/radix64.h> #include <util/radix64.h>
#include <util/rsdir.h>
#include "file_sharing_defaults.h" #include "file_sharing_defaults.h"
#include "filelist_io.h" #include "filelist_io.h"
@ -30,12 +31,16 @@ FileTree *FileTree::create(const std::string& radix64_string)
return ft ; return ft ;
} }
void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote) void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote,bool remove_top_dirs)
{ {
if(ft.mDirs.size() <= index) if(ft.mDirs.size() <= index)
ft.mDirs.resize(index+1) ; ft.mDirs.resize(index+1) ;
ft.mDirs[index].name = dd.name ; if(remove_top_dirs)
ft.mDirs[index].name = RsDirUtil::getTopDir(dd.name) ;
else
ft.mDirs[index].name = dd.name ;
ft.mDirs[index].subfiles.clear(); ft.mDirs[index].subfiles.clear();
ft.mDirs[index].subdirs.clear(); ft.mDirs[index].subdirs.clear();
@ -62,7 +67,7 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di
else if(dd.children[i].type == DIR_TYPE_DIR) else if(dd.children[i].type == DIR_TYPE_DIR)
{ {
ft.mDirs[index].subdirs.push_back(ft.mDirs.size()); ft.mDirs[index].subdirs.push_back(ft.mDirs.size());
recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote) ; recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote,remove_top_dirs) ;
} }
else else
std::cerr << "(EE) Unsupported DirDetails type." << std::endl; std::cerr << "(EE) Unsupported DirDetails type." << std::endl;
@ -86,11 +91,11 @@ bool FileTreeImpl::getDirectoryContent(uint32_t index,std::string& name,std::vec
return true ; return true ;
} }
FileTree *FileTree::create(const DirDetails& dd, bool remote) FileTree *FileTree::create(const DirDetails& dd, bool remote,bool remove_top_dirs)
{ {
FileTreeImpl *ft = new FileTreeImpl ; FileTreeImpl *ft = new FileTreeImpl ;
FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote) ; FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote,remove_top_dirs) ;
return ft ; return ft ;
} }

View File

@ -19,7 +19,7 @@ public:
protected: protected:
void recurs_print(uint32_t index,const std::string& indent) const; void recurs_print(uint32_t index,const std::string& indent) const;
static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote); static void recurs_buildFileTree(FileTreeImpl& ft, uint32_t index, const DirDetails& dd, bool remote, bool remove_top_dirs);
struct DirData { struct DirData {
std::string name; std::string name;

View File

@ -144,7 +144,7 @@ class FileTree
public: public:
virtual ~FileTree() {} virtual ~FileTree() {}
static FileTree *create(const DirDetails& dd, bool remote) ; static FileTree *create(const DirDetails& dd, bool remote, bool remove_top_dirs = true) ;
static FileTree *create(const std::string& radix64_string) ; static FileTree *create(const std::string& radix64_string) ;
virtual std::string toRadix64() const =0 ; virtual std::string toRadix64() const =0 ;