| 1 |  |  | /** | 
    
    | 2 |  |  |  * This file is part of the CernVM File System. | 
    
    | 3 |  |  |  */ | 
    
    | 4 |  |  |  | 
    
    | 5 |  |  | #define __STDC_FORMAT_MACROS | 
    
    | 6 |  |  |  | 
    
    | 7 |  |  | #include "cvmfs_config.h" | 
    
    | 8 |  |  | #include "glue_buffer.h" | 
    
    | 9 |  |  |  | 
    
    | 10 |  |  | #include <cassert> | 
    
    | 11 |  |  | #include <cstdlib> | 
    
    | 12 |  |  | #include <cstring> | 
    
    | 13 |  |  |  | 
    
    | 14 |  |  | #include <string> | 
    
    | 15 |  |  | #include <vector> | 
    
    | 16 |  |  |  | 
    
    | 17 |  |  | #include "logging.h" | 
    
    | 18 |  |  | #include "platform.h" | 
    
    | 19 |  |  | #include "smalloc.h" | 
    
    | 20 |  |  |  | 
    
    | 21 |  |  | using namespace std;  // NOLINT | 
    
    | 22 |  |  |  | 
    
    | 23 |  |  | namespace glue { | 
    
    | 24 |  |  |  | 
    
    | 25 |  |  | PathStore &PathStore::operator= (const PathStore &other) { | 
    
    | 26 |  |  |   if (&other == this) | 
    
    | 27 |  |  |     return *this; | 
    
    | 28 |  |  |  | 
    
    | 29 |  |  |   delete string_heap_; | 
    
    | 30 |  |  |   CopyFrom(other); | 
    
    | 31 |  |  |   return *this; | 
    
    | 32 |  |  | } | 
    
    | 33 |  |  |  | 
    
    | 34 |  |  |  | 
    
    | 35 |  |  | PathStore::PathStore(const PathStore &other) { | 
    
    | 36 |  |  |   CopyFrom(other); | 
    
    | 37 |  |  | } | 
    
    | 38 |  |  |  | 
    
    | 39 |  |  |  | 
    
    | 40 |  |  | void PathStore::CopyFrom(const PathStore &other) { | 
    
    | 41 |  |  |   map_ = other.map_; | 
    
    | 42 |  |  |  | 
    
    | 43 |  |  |   string_heap_ = new StringHeap(other.string_heap_->used()); | 
    
    | 44 |  |  |   shash::Md5 empty_path = map_.empty_key(); | 
    
    | 45 |  |  |   for (unsigned i = 0; i < map_.capacity(); ++i) { | 
    
    | 46 |  |  |     if (map_.keys()[i] != empty_path) { | 
    
    | 47 |  |  |       (map_.values() + i)->name = | 
    
    | 48 |  |  |       string_heap_->AddString(map_.values()[i].name.length(), | 
    
    | 49 |  |  |                               map_.values()[i].name.data()); | 
    
    | 50 |  |  |     } | 
    
    | 51 |  |  |   } | 
    
    | 52 |  |  | } | 
    
    | 53 |  |  |  | 
    
    | 54 |  |  |  | 
    
    | 55 |  |  | //------------------------------------------------------------------------------ | 
    
    | 56 |  |  |  | 
    
    | 57 |  |  |  | 
    
    | 58 |  | 36 | void InodeTracker::InitLock() { | 
    
    | 59 |  |  |   lock_ = | 
    
    | 60 |  | 36 |     reinterpret_cast<pthread_mutex_t *>(smalloc(sizeof(pthread_mutex_t))); | 
    
    | 61 |  | 36 |   int retval = pthread_mutex_init(lock_, NULL); | 
    
    | 62 | ✗✓ | 36 |   assert(retval == 0); | 
    
    | 63 |  | 36 | } | 
    
    | 64 |  |  |  | 
    
    | 65 |  |  |  | 
    
    | 66 |  |  | void InodeTracker::CopyFrom(const InodeTracker &other) { | 
    
    | 67 |  |  |   assert(other.version_ == kVersion); | 
    
    | 68 |  |  |   version_ = kVersion; | 
    
    | 69 |  |  |   path_map_ = other.path_map_; | 
    
    | 70 |  |  |   inode_map_ = other.inode_map_; | 
    
    | 71 |  |  |   inode_references_ = other.inode_references_; | 
    
    | 72 |  |  |   statistics_ = other.statistics_; | 
    
    | 73 |  |  | } | 
    
    | 74 |  |  |  | 
    
    | 75 |  |  |  | 
    
    | 76 |  | 36 | InodeTracker::InodeTracker() { | 
    
    | 77 |  | 36 |   version_ = kVersion; | 
    
    | 78 |  | 36 |   InitLock(); | 
    
    | 79 |  | 36 | } | 
    
    | 80 |  |  |  | 
    
    | 81 |  |  |  | 
    
    | 82 |  |  | InodeTracker::InodeTracker(const InodeTracker &other) { | 
    
    | 83 |  |  |   CopyFrom(other); | 
    
    | 84 |  |  |   InitLock(); | 
    
    | 85 |  |  | } | 
    
    | 86 |  |  |  | 
    
    | 87 |  |  |  | 
    
    | 88 |  |  | InodeTracker &InodeTracker::operator= (const InodeTracker &other) { | 
    
    | 89 |  |  |   if (&other == this) | 
    
    | 90 |  |  |     return *this; | 
    
    | 91 |  |  |  | 
    
    | 92 |  |  |   CopyFrom(other); | 
    
    | 93 |  |  |   return *this; | 
    
    | 94 |  |  | } | 
    
    | 95 |  |  |  | 
    
    | 96 |  |  |  | 
    
    | 97 |  | 36 | InodeTracker::~InodeTracker() { | 
    
    | 98 |  | 36 |   pthread_mutex_destroy(lock_); | 
    
    | 99 |  | 36 |   free(lock_); | 
    
    | 100 |  | 36 | } | 
    
    | 101 |  |  |  | 
    
    | 102 | ✓✗✓✗ 
 | 45 | }  // namespace glue |