CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sync_item_tar.cc
Go to the documentation of this file.
1 
5 #include "sync_item_tar.h"
6 
7 #include <string>
8 
9 #include "directory_entry.h"
10 #include "duplex_libarchive.h"
12 #include "platform.h"
13 #include "sync_union_tarball.h"
14 #include "util_concurrency.h"
15 
16 namespace publish {
17 
18 SyncItemTar::SyncItemTar(const std::string &relative_parent_path,
19  const std::string &filename, struct archive *archive,
20  struct archive_entry *entry,
21  Signal *read_archive_signal,
22  const SyncUnion *union_engine)
23  : SyncItem(relative_parent_path, filename, union_engine, kItemUnknown),
24  archive_(archive),
25  archive_entry_(entry),
26  obtained_tar_stat_(false),
27  read_archive_signal_(read_archive_signal) {
29 }
30 
31 void SyncItemTar::StatScratch(const bool refresh) const {
32  if (scratch_stat_.obtained && !refresh) return;
35  scratch_stat_.obtained = true;
36 }
37 
40  switch (archive_entry_filetype(archive_entry_)) {
41  case AE_IFREG: {
42  return kItemFile;
43  break;
44  }
45  case AE_IFLNK: {
46  return kItemSymlink;
47  break;
48  }
49  case AE_IFSOCK: {
50  return kItemSocket;
51  break;
52  }
53  case AE_IFCHR: {
54  return kItemCharacterDevice;
55  break;
56  }
57  case AE_IFBLK: {
58  return kItemBlockDevice;
59  break;
60  }
61  case AE_IFDIR: {
62  return kItemDir;
63  break;
64  }
65  case AE_IFIFO: {
66  return kItemFifo;
67  break;
68  }
69  default:
70  return kItemUnknown;
71  break;
72  }
73 }
74 
75 bool SyncItemTar::IsType(const SyncItemType expected_type) const {
76  if (scratch_type_ == kItemUnknown) {
78  }
79  return scratch_type_ == expected_type;
80 }
81 
84  if (obtained_tar_stat_) return tar_stat_;
85 
86  const struct stat *entry_stat = archive_entry_stat(archive_entry_);
87  assert(NULL != entry_stat);
88 
89  tar_stat_.st_mode = entry_stat->st_mode;
90  tar_stat_.st_uid = entry_stat->st_uid;
91  tar_stat_.st_gid = entry_stat->st_gid;
92  tar_stat_.st_rdev = entry_stat->st_rdev;
93  tar_stat_.st_size = entry_stat->st_size;
94  tar_stat_.st_mtime = entry_stat->st_mtime;
95  tar_stat_.st_nlink = entry_stat->st_nlink;
96 
97  if (IsDirectory()) {
98  tar_stat_.st_size = 4096;
99  }
100 
101  obtained_tar_stat_ = true;
102 
103  return tar_stat_;
104 }
105 
108 
110 
111  // inode and parent inode is determined at runtime of client
113 
114  // tarfiles do not keep information about the linkcount, so it should always
115  // appear as zero
116  assert(this->tar_stat_.st_nlink == 0);
117  dirent.linkcount_ = 1;
118 
119  dirent.mode_ = this->tar_stat_.st_mode;
120  dirent.uid_ = this->tar_stat_.st_uid;
121  dirent.gid_ = this->tar_stat_.st_gid;
122  dirent.size_ = this->tar_stat_.st_size;
123  dirent.mtime_ = this->tar_stat_.st_mtime;
124  dirent.checksum_ = this->GetContentHash();
125  dirent.is_external_file_ = this->IsExternalData();
127 
128  dirent.name_.Assign(this->filename().data(), this->filename().length());
129 
130  if (this->IsSymlink()) {
131  std::string symlink(archive_entry_symlink(archive_entry_));
132  dirent.symlink_.Assign(symlink.c_str(), symlink.length());
133  }
134 
135  if (this->IsCharacterDevice() || this->IsBlockDevice()) {
136  dirent.size_ = makedev(major(tar_stat_.st_rdev), minor(tar_stat_.st_rdev));
137  }
138 
139  assert(dirent.IsRegular() || dirent.IsDirectory() || dirent.IsLink() ||
140  dirent.IsSpecial());
141 
142  return dirent;
143 }
144 
148 }
149 } // namespace publish
bool IsSpecial() const
struct stat64 platform_stat64
bool IsDirectory() const
shash::Any GetContentHash() const
Definition: sync_item.h:121
inode_t inode_
platform_stat64 GetStatFromTar() const
void Assign(const char *chars, const unsigned length)
Definition: shortstring.h:53
gid_t gid_
struct archive * archive_
Definition: sync_item_tar.h:39
bool IsBlockDevice() const
Definition: sync_item.h:77
bool IsDirectory() const
Definition: sync_item.h:64
bool IsCharacterDevice() const
Definition: sync_item.h:76
assert((mem||(size==0))&&"Out Of Memory")
virtual void StatScratch(const bool refresh) const
uint64_t size_
SyncItemType scratch_type_
Definition: sync_item.h:276
NameString name_
platform_stat64 stat
Definition: sync_item.h:259
zlib::Algorithms compression_algorithm_
bool IsLink() const
bool IsRegular() const
std::string GetUnionPath() const
Definition: sync_item.cc:249
uint32_t linkcount_
bool is_external_file_
zlib::Algorithms GetCompressionAlgorithm() const
Definition: sync_item.h:127
time_t mtime_
static const inode_t kInvalidInode
virtual bool IsType(const SyncItemType expected_type) const
EntryStat scratch_stat_
Definition: sync_item.h:269
SyncItemTar(const std::string &relative_parent_path, const std::string &filename, struct archive *archive, struct archive_entry *entry, Signal *read_archive_signal, const SyncUnion *union_engine)
platform_stat64 tar_stat_
Definition: sync_item_tar.h:42
Signal * read_archive_signal_
Definition: sync_item_tar.h:44
unsigned int mode_
SyncItemType
Definition: sync_item.h:29
struct archive_entry * archive_entry_
Definition: sync_item_tar.h:40
shash::Any checksum_
bool IsSymlink() const
Definition: sync_item.h:68
std::string filename() const
Definition: sync_item.h:174
bool IsExternalData() const
Definition: sync_item.h:81
bool obtained
Definition: sync_item.h:257
virtual IngestionSource * CreateIngestionSource() const
LinkString symlink_
int error_code
Definition: sync_item.h:258
virtual SyncItemType GetScratchFiletype() const
virtual catalog::DirectoryEntryBase CreateBasicCatalogDirent() const
uid_t uid_