GCC Code Coverage Report


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