GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/sync_item_dummy.h
Date: 2025-02-09 02:34:19
Exec Total Coverage
Lines: 10 36 27.8%
Branches: 1 20 5.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System
3 */
4
5 #ifndef CVMFS_SYNC_ITEM_DUMMY_H_
6 #define CVMFS_SYNC_ITEM_DUMMY_H_
7
8 #include "sync_item.h"
9
10 #include <ctime>
11 #include <string>
12
13 #include "ingestion/ingestion_source.h"
14 #include "sync_union_tarball.h"
15
16 namespace publish {
17
18 class SyncItemDummyCatalog : public SyncItem {
19 friend class SyncUnionTarball;
20
21 protected:
22 SyncItemDummyCatalog(const std::string &relative_parent_path,
23 const SyncUnion *union_engine)
24 : SyncItem(relative_parent_path, ".cvmfscatalog", union_engine,
25 kItemFile) {}
26
27 public:
28 bool IsType(const SyncItemType expected_type) const {
29 return expected_type == kItemFile;
30 }
31
32 catalog::DirectoryEntryBase CreateBasicCatalogDirent(
33 bool /* enable_mtime_ns */) const
34 {
35 catalog::DirectoryEntryBase dirent;
36 std::string name(".cvmfscatalog");
37 dirent.inode_ = catalog::DirectoryEntry::kInvalidInode;
38 dirent.linkcount_ = 1;
39 dirent.mode_ =
40 S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
41 dirent.uid_ = getuid();
42 dirent.gid_ = getgid();
43 dirent.size_ = 0;
44 dirent.mtime_ = time(NULL);
45 dirent.checksum_ = this->GetContentHash();
46 dirent.is_external_file_ = false;
47 dirent.compression_algorithm_ = this->GetCompressionAlgorithm();
48
49 dirent.name_.Assign(name.data(), name.length());
50
51 return dirent;
52 }
53
54 IngestionSource *CreateIngestionSource() const {
55 return new StringIngestionSource("", GetUnionPath());
56 }
57
58 void StatScratch(const bool /* refresh */) const { return; }
59
60 SyncItemType GetScratchFiletype() const { return kItemFile; }
61
62 void MakePlaceholderDirectory() const {}
63 };
64
65 /*
66 * This class represents dummy directories that we know are going to be there
67 * but we still haven't found yet. This is possible in the extraction of
68 * tarball, where the files are not extracted in order (root to leaves) but in a
69 * random fashion.
70 */
71 class SyncItemDummyDir : public SyncItemNative {
72 friend class SyncUnionTarball;
73
74 public:
75 virtual catalog::DirectoryEntryBase CreateBasicCatalogDirent(
76 bool enable_mtime_ns) const;
77 SyncItemType GetScratchFiletype() const;
78 virtual void MakePlaceholderDirectory() const { rdonly_type_ = kItemDir; }
79
80 protected:
81 SyncItemDummyDir(const std::string &relative_parent_path,
82 const std::string &filename, const SyncUnion *union_engine,
83 const SyncItemType entry_type)
84 : SyncItemNative(relative_parent_path, filename, union_engine,
85 entry_type) {
86 assert(kItemDir == entry_type);
87
88 scratch_stat_.obtained = true;
89 scratch_stat_.stat.st_mode = kPermision;
90 scratch_stat_.stat.st_nlink = 1;
91 scratch_stat_.stat.st_uid = getuid();
92 scratch_stat_.stat.st_gid = getgid();
93 }
94 5 SyncItemDummyDir(const std::string &relative_parent_path,
95 const std::string &filename, const SyncUnion *union_engine,
96 const SyncItemType entry_type, uid_t uid, gid_t gid)
97 5 : SyncItemNative(relative_parent_path, filename, union_engine,
98 5 entry_type) {
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 assert(kItemDir == entry_type);
100
101 5 scratch_stat_.obtained = true;
102 5 scratch_stat_.stat.st_mode = kPermision;
103 5 scratch_stat_.stat.st_nlink = 1;
104 5 scratch_stat_.stat.st_uid = uid;
105 5 scratch_stat_.stat.st_gid = gid;
106 5 }
107
108 private:
109 static const mode_t kPermision = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR |
110 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
111 };
112
113 } // namespace publish
114
115 #endif // CVMFS_SYNC_ITEM_DUMMY_H_
116