1- From bed541b7ceafaf75f67911ef64e231569b8eec84 Mon Sep 17 00:00:00 2001
1+ From ef2e53818f93005d1dc2d96eaa36519069fa979d Mon Sep 17 00:00:00 2001
22From: Sam Meluch <sammeluch@microsoft.com>
33Date: Tue, 30 Apr 2024 13:56:44 -0700
44Subject: [PATCH] Add virtual repo snapshot feature to tdnf
55
66---
77 client/config.c | 5 +
8- client/prototypes.h | 3 +-
8+ client/prototypes.h | 9 +-
99 client/repo.c | 50 +-
10+ client/repolist.c | 66 ++
1011 common/config.h | 1 +
11- etc/bash_completion.d/tdnf-completion.bash | 2 +-
12+ etc/bash_completion.d/tdnf-completion.bash | 7 +-
1213 include/tdnferror.h | 9 +
13- include/tdnftypes.h | 2 +
14+ include/tdnftypes.h | 3 +
1415 solv/defines.h | 29 +
1516 solv/includes.h | 6 +-
1617 solv/prototypes.h | 3 +-
1718 solv/tdnfrepo.c | 783 ++++++++++++++++++++-
18- tools/cli/lib/help.c | 1 +
19- tools/cli/lib/parseargs.c | 1 +
20- 13 files changed, 878 insertions(+), 17 deletions(-)
19+ tools/cli/lib/help.c | 2 +
20+ tools/cli/lib/parseargs.c | 2 +
21+ 14 files changed, 958 insertions(+), 17 deletions(-)
2122
2223diff --git a/client/config.c b/client/config.c
2324index 8ddcc7a..805fff1 100644
@@ -43,7 +44,7 @@ index 8ddcc7a..805fff1 100644
4344 {
4445 pConf->nCleanRequirementsOnRemove = isTrue(cn->value);
4546diff --git a/client/prototypes.h b/client/prototypes.h
46- index bb7fba1..cb8a8d3 100644
47+ index bb7fba1..ddac483 100644
4748--- a/client/prototypes.h
4849+++ b/client/prototypes.h
4950@@ -586,7 +586,8 @@ uint32_t
@@ -56,8 +57,21 @@ index bb7fba1..cb8a8d3 100644
5657 );
5758
5859 uint32_t
60+ @@ -770,6 +771,12 @@ TDNFAlterRepoState(
61+ const char* pszId
62+ );
63+
64+ + uint32_t
65+ + TDNFExcludeFromSnapshot(
66+ + PTDNF_REPO_DATA pRepos,
67+ + const char* pszId
68+ + );
69+ +
70+ uint32_t
71+ TDNFCloneRepo(
72+ PTDNF_REPO_DATA pRepoIn,
5973diff --git a/client/repo.c b/client/repo.c
60- index b6073e2..0331796 100644
74+ index 809c39d..95f7694 100644
6175--- a/client/repo.c
6276+++ b/client/repo.c
6377@@ -36,6 +36,8 @@ TDNFInitRepo(
@@ -91,7 +105,7 @@ index b6073e2..0331796 100644
91105 pPool = pSack->pPool;
92106
93107 dwError = TDNFGetCachePath(pTdnf, pRepoData,
94- @@ -82 ,20 +99 ,27 @@ TDNFInitRepo(
108+ @@ -89 ,20 +106 ,27 @@ TDNFInitRepo(
95109 pRepo->appdata = pSolvRepoInfo;
96110
97111 if (pRepoData->nHasMetaData) {
@@ -104,7 +118,7 @@ index b6073e2..0331796 100644
104118-
105119- if (nUseMetaDataCache == 0) {
106120- dwError = TDNFInitRepoFromMetadata(pRepo, pRepoData->pszId, pRepoMD);
107- + if (pszSnapshotTime != NULL) {
121+ + if (!pRepoData->nExcludeSnapshot && pszSnapshotTime != NULL) {
108122+ dwError = TDNFInitRepoFromMetadata(pRepo, pRepoData->pszId, pRepoMD, pszSnapshotTime);
109123 BAIL_ON_TDNF_ERROR(dwError);
110124+ } else {
@@ -129,7 +143,7 @@ index b6073e2..0331796 100644
129143 } else {
130144 dwError = SolvReadRpmsFromDirectory(pRepo, pRepoData->ppszBaseUrls[0]);
131145 BAIL_ON_TDNF_ERROR(dwError);
132- @@ -135 ,7 +159 ,8 @@ uint32_t
146+ @@ -142 ,7 +166 ,8 @@ uint32_t
133147 TDNFInitRepoFromMetadata(
134148 Repo *pRepo,
135149 const char* pszRepoName,
@@ -139,7 +153,7 @@ index b6073e2..0331796 100644
139153 )
140154 {
141155 uint32_t dwError = 0;
142- @@ -152 ,7 +177 ,8 @@ TDNFInitRepoFromMetadata(
156+ @@ -159 ,7 +184 ,8 @@ TDNFInitRepoFromMetadata(
143157 pRepoMD->pszPrimary,
144158 pRepoMD->pszFileLists,
145159 pRepoMD->pszUpdateInfo,
@@ -149,6 +163,111 @@ index b6073e2..0331796 100644
149163 cleanup:
150164 return dwError;
151165
166+ diff --git a/client/repolist.c b/client/repolist.c
167+ index df37959..be94f6c 100644
168+ --- a/client/repolist.c
169+ +++ b/client/repolist.c
170+ @@ -358,6 +358,7 @@ TDNFCreateRepo(
171+ BAIL_ON_TDNF_ERROR(dwError);
172+
173+ pRepo->nEnabled = TDNF_REPO_DEFAULT_ENABLED;
174+ + pRepo->nExcludeSnapshot = 0;
175+ pRepo->nHasMetaData = 1;
176+ pRepo->nSkipIfUnavailable = TDNF_REPO_DEFAULT_SKIP;
177+ pRepo->nGPGCheck = TDNF_REPO_DEFAULT_GPGCHECK;
178+ @@ -655,6 +656,7 @@ TDNFRepoListFinalize(
179+ PTDNF_CMD_OPT pSetOpt = NULL;
180+ PTDNF_REPO_DATA pRepo = NULL;
181+ int nRepoidSeen = 0;
182+ + char ** ppszRepos = NULL;
183+
184+ if(!pTdnf || !pTdnf->pArgs || !pTdnf->pRepos)
185+ {
186+ @@ -695,6 +697,22 @@ TDNFRepoListFinalize(
187+ 1,
188+ pSetOpt->pszOptValue);
189+ }
190+ + else if (strcmp(pSetOpt->pszOptName, "snapshotexcluderepos") == 0)
191+ + {
192+ + ppszRepos = NULL;
193+ + int i = 0;
194+ + dwError = TDNFSplitStringToArray(pSetOpt->pszOptValue, ",", &ppszRepos);
195+ + BAIL_ON_TDNF_ERROR(dwError);
196+ +
197+ + while (ppszRepos && ppszRepos[i]){
198+ + dwError = TDNFExcludeFromSnapshot(
199+ + pTdnf->pRepos,
200+ + ppszRepos[i]);
201+ + BAIL_ON_TDNF_ERROR(dwError);
202+ + i++;
203+ + }
204+ +
205+ + }
206+ BAIL_ON_TDNF_ERROR(dwError);
207+ }
208+
209+ @@ -736,6 +754,7 @@ TDNFRepoListFinalize(
210+ BAIL_ON_TDNF_ERROR(dwError);
211+ }
212+ cleanup:
213+ + TDNFFreeStringArray(ppszRepos);
214+ return dwError;
215+ error:
216+ goto cleanup;
217+ @@ -787,6 +806,53 @@ error:
218+ goto cleanup;
219+ }
220+
221+ + uint32_t
222+ + TDNFExcludeFromSnapshot(
223+ + PTDNF_REPO_DATA pRepos,
224+ + const char* pszId
225+ + )
226+ + {
227+ + uint32_t dwError = 0;
228+ + int nIsGlob = 0;
229+ + if(!pRepos || IsNullOrEmptyString(pszId))
230+ + {
231+ + dwError = ERROR_TDNF_INVALID_PARAMETER;
232+ + BAIL_ON_TDNF_ERROR(dwError);
233+ + }
234+ +
235+ + nIsGlob = TDNFIsGlob(pszId);
236+ +
237+ + for (int nMatch = 0; pRepos; pRepos = pRepos->pNext)
238+ + {
239+ + if(nIsGlob)
240+ + {
241+ + if(!fnmatch(pszId, pRepos->pszId, 0))
242+ + {
243+ + nMatch = 1;
244+ + }
245+ + }
246+ + else if(!strcmp(pRepos->pszId, pszId))
247+ + {
248+ + nMatch = 1;
249+ + }
250+ +
251+ + if(nMatch)
252+ + {
253+ + pRepos->nExcludeSnapshot = 1;
254+ + if(!nIsGlob)
255+ + {
256+ + break;
257+ + }
258+ + }
259+ + }
260+ +
261+ + cleanup:
262+ + return dwError;
263+ +
264+ + error:
265+ + goto cleanup;
266+ + }
267+ +
268+ uint32_t
269+ TDNFCloneRepo(
270+ PTDNF_REPO_DATA pRepoIn,
152271diff --git a/common/config.h b/common/config.h
153272index 222a448..364f7ec 100644
154273--- a/common/config.h
@@ -162,15 +281,27 @@ index 222a448..364f7ec 100644
162281 #define TDNF_CONF_KEY_REPODIR "repodir" // typo, keep for back compatibility
163282 #define TDNF_CONF_KEY_REPOSDIR "reposdir"
164283diff --git a/etc/bash_completion.d/tdnf-completion.bash b/etc/bash_completion.d/tdnf-completion.bash
165- index 4e48040..3f310d4 100644
284+ index 4e48040..46a6201 100644
166285--- a/etc/bash_completion.d/tdnf-completion.bash
167286+++ b/etc/bash_completion.d/tdnf-completion.bash
168- @@ -92,7 +92,7 @@ _tdnf()
287+ @@ -26,6 +26,11 @@ _tdnf__process_if_prev_is_option()
288+ COMPREPLY=( $(compgen -W "$opts" -- $cur) )
289+ return 0
290+ ;;
291+ + --snapshotexcluderepos)
292+ + opts=`tdnf repolist enabled | awk '{if (NR > 1) print $1}'`
293+ + COMPREPLY=( $(compgen -W "$opts" -- $cur) )
294+ + return 0
295+ + ;;
296+ --installroot)
297+ COMPREPLY=( $(compgen -d -- $cur) )
298+ return 0
299+ @@ -92,7 +97,7 @@ _tdnf()
169300 {
170301 local c=0 cur __opts __cmds
171302 COMPREPLY=()
172303- __opts="--assumeno --assumeyes --cacheonly --debugsolver --disableexcludes --disableplugin --disablerepo --downloaddir --downloadonly --enablerepo --enableplugin --exclude --installroot --noautoremove --nogpgcheck --noplugins --quiet --reboot --refresh --releasever --repo --repofrompath --repoid --rpmverbosity --security --sec --setopt --skip --skipconflicts --skipdigest --skipsignature --skipobsoletes --testonly --version --available --duplicates --extras --file --installed --whatdepends --whatrequires --whatenhances --whatobsoletes --whatprovides --whatrecommends --whatrequires --whatsuggests --whatsupplements --depends --enhances --list --obsoletes --provides --recommends --requires --requires --suggests --source --supplements --arch --delete --download --download --gpgcheck --metadata --newest --norepopath --source --urls"
173- + __opts="--assumeno --assumeyes --cacheonly --debugsolver --disableexcludes --disableplugin --disablerepo --downloaddir --downloadonly --enablerepo --enableplugin --snapshottime -- exclude --installroot --noautoremove --nogpgcheck --noplugins --quiet --reboot --refresh --releasever --repo --repofrompath --repoid --rpmverbosity --security --sec --setopt --skip --skipconflicts --skipdigest --skipsignature --skipobsoletes --testonly --version --available --duplicates --extras --file --installed --whatdepends --whatrequires --whatenhances --whatobsoletes --whatprovides --whatrecommends --whatrequires --whatsuggests --whatsupplements --depends --enhances --list --obsoletes --provides --recommends --requires --requires --suggests --source --supplements --arch --delete --download --download --gpgcheck --metadata --newest --norepopath --source --urls"
304+ + __opts="--assumeno --assumeyes --cacheonly --debugsolver --disableexcludes --disableplugin --disablerepo --downloaddir --downloadonly --enablerepo --enableplugin --exclude --installroot --noautoremove --nogpgcheck --noplugins --quiet --reboot --refresh --releasever --repo --repofrompath --repoid --rpmverbosity --security --sec --setopt --skip --skipconflicts --skipdigest --skipsignature --skipobsoletes --snapshotexcluderepos --snapshottime --testonly --version --available --duplicates --extras --file --installed --whatdepends --whatrequires --whatenhances --whatobsoletes --whatprovides --whatrecommends --whatrequires --whatsuggests --whatsupplements --depends --enhances --list --obsoletes --provides --recommends --requires --requires --suggests --source --supplements --arch --delete --download --download --gpgcheck --metadata --newest --norepopath --source --urls"
174305 __cmds="autoerase autoremove check check-local check-update clean distro-sync downgrade erase help history info install list makecache mark provides whatprovides reinstall remove repolist repoquery reposync search update update-to updateinfo upgrade upgrade-to"
175306 cur="${COMP_WORDS[COMP_CWORD]}"
176307 _tdnf__process_if_prev_is_option && return 0
@@ -195,7 +326,7 @@ index c9349a0..02b8d4c 100644
195326 #define ERROR_TDNF_PLUGIN_BASE 2000
196327
197328diff --git a/include/tdnftypes.h b/include/tdnftypes.h
198- index a806010..f371430 100644
329+ index a806010..b95c81f 100644
199330--- a/include/tdnftypes.h
200331+++ b/include/tdnftypes.h
201332@@ -9,6 +9,7 @@
@@ -214,6 +345,14 @@ index a806010..f371430 100644
214345 char* pszCacheDir;
215346 char* pszPersistDir;
216347 char* pszProxy;
348+ @@ -274,6 +276,7 @@ typedef struct _TDNF_CONF
349+ typedef struct _TDNF_REPO_DATA
350+ {
351+ int nEnabled;
352+ + int nExcludeSnapshot;
353+ int nSkipIfUnavailable;
354+ int nGPGCheck;
355+ int nHasMetaData;
217356diff --git a/solv/defines.h b/solv/defines.h
218357index 38f5ab1..ddb3355 100644
219358--- a/solv/defines.h
@@ -1107,26 +1246,28 @@ index c27b907..fec3ba7 100644
11071246 return dwError;
11081247
11091248diff --git a/tools/cli/lib/help.c b/tools/cli/lib/help.c
1110- index bc4cf83..86c34e7 100644
1249+ index bc4cf83..6c1d349 100644
11111250--- a/tools/cli/lib/help.c
11121251+++ b/tools/cli/lib/help.c
1113- @@ -23,6 +23,7 @@ static const char *help_msg =
1114- " [--downloadonly]\n"
1115- " [--enablerepo=<repoid>]\n"
1116- " [--enableplugin=<plugin_name>]\n"
1252+ @@ -44,6 +44,8 @@ static const char *help_msg =
1253+ " [--skipdigest]\n"
1254+ " [--skipsignature]\n"
1255+ " [--skipobsoletes]\n"
1256+ + " [--snapshotexcluderepos=<repoid>[,<repoid2>,...]\n"
11171257+ " [--snapshottime=<POSIX_time>]\n"
1118- " [--exclude [file1,file2,...] ]\n"
1119- " [--installroot [path]] \n"
1120- " [--noautoremove] \n"
1258+ " [--testonly ]\n"
1259+ " [--version]\n \n"
1260+ "repoquery select options: \n"
11211261diff --git a/tools/cli/lib/parseargs.c b/tools/cli/lib/parseargs.c
1122- index 0558611..18c84fc 100644
1262+ index 4421927..9c5e282 100644
11231263--- a/tools/cli/lib/parseargs.c
11241264+++ b/tools/cli/lib/parseargs.c
1125- @@ -70,6 +70,7 @@ static struct option pstOptions[] =
1265+ @@ -70,6 +70,8 @@ static struct option pstOptions[] =
11261266 {"skipdigest", no_argument, 0, 0}, //--skipdigest to skip verifying RPM digest
11271267 {"skipobsoletes", no_argument, 0, 0}, //--skipobsoletes to skip obsolete problems
11281268 {"skipsignature", no_argument, 0, 0}, //--skipsignature to skip verifying RPM signatures
1129- + {"snapshottime",required_argument, 0, 0}, //--snapshottime
1269+ + {"snapshotexcluderepos", required_argument, 0, 0}, //--snapshotexcluderepos
1270+ + {"snapshottime", required_argument, 0, 0}, //--snapshottime
11301271 {"source", no_argument, &_opt.nSource, 1},
11311272 {"testonly", no_argument, &_opt.nTestOnly, 1},
11321273 {"verbose", no_argument, &_opt.nVerbose, 1}, //-v --verbose
0 commit comments