From fa1eb4c77ef5bf4decb80f6de5f51c220c6698e0 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 12 Sep 2007 15:24:20 +0000 Subject: [PATCH] - Assert assert leading and trailing '/' on pathnames in ctor. - Remove empty dummy operator= causing data loss --- zypp/DiskUsage.cc | 8 ++++---- zypp/DiskUsage.h | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/zypp/DiskUsage.cc b/zypp/DiskUsage.cc index b2a6c9b..61af853 100644 --- a/zypp/DiskUsage.cc +++ b/zypp/DiskUsage.cc @@ -29,8 +29,8 @@ namespace zypp iterator fst = begin(); for ( ; fst != end() && !fst->isBelow( ret ); ++fst ) ; // seek 1st equal or below - - bool found = false; + + bool found = false; if ( fst != end() ) { iterator lst = fst; found = true; @@ -50,7 +50,7 @@ namespace zypp { dname.insert(dname.begin(), '/'); } - + Entry tmp( dname ); tmp._size = ret._size; @@ -73,7 +73,7 @@ namespace zypp } } } - + return ret; } diff --git a/zypp/DiskUsage.h b/zypp/DiskUsage.h index c1501c9..18fe1a9 100644 --- a/zypp/DiskUsage.h +++ b/zypp/DiskUsage.h @@ -22,7 +22,7 @@ namespace zypp class DiskUsage { public: /** - * @short Holds data about how much space will be needed per directory + * @short Holds data about how much space will be needed per directory. **/ struct Entry { Entry() : _size(0), _files(0) {}; @@ -30,8 +30,15 @@ namespace zypp const unsigned size_r = 0, const unsigned files_r = 0) : path(path_r), _size(size_r), _files(files_r) - {} - const std::string path; + { + // assert leading and trailing '/' + if ( ! path.empty() ) + { + if ( *path.begin() != '/' ) path.insert( path.begin(), '/' ); + if ( *path.rbegin() != '/' ) path.insert( path.end(), '/' ); + } + } + std::string path; mutable unsigned _size; mutable unsigned _files; friend std::ostream & operator<<( std::ostream & str, const Entry & obj ); @@ -62,12 +69,6 @@ namespace zypp } /** - * - **/ - const Entry & operator=( const Entry & rhs ) const { - return rhs; - } - /** * Numerical operation based on size and files values. **/ const Entry & operator+=( const Entry & rhs ) const { -- 2.7.4