Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --repofromdir option #353

Merged
merged 5 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 18 additions & 49 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,14 @@ TDNFCheckLocalPackages(
)
{
uint32_t dwError = 0;
char* pszRPMPath = NULL;
DIR *pDir = NULL;
struct dirent *pEnt = NULL;
Repo *pCmdlineRepo = 0;
Id dwPkgAdded = 0;
Queue queueJobs = {0};
Solver *pSolv = NULL;
uint32_t dwPackagesFound = 0;
uint32_t count = 0;
Pool *pCmdLinePool = NULL;
TDNF_SKIPPROBLEM_TYPE dwSkipProblem = SKIPPROBLEM_NONE;
Solvable *s = NULL;
Id p;

if(!pTdnf || !pTdnf->pSack || !pTdnf->pSack->pPool || !pszLocalPath)
{
Expand All @@ -279,12 +277,7 @@ TDNFCheckLocalPackages(
}

queue_init(&queueJobs);
pDir = opendir(pszLocalPath);
if(pDir == NULL)
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

pr_info("Checking all packages from: %s\n", pszLocalPath);

pCmdLinePool = pool_create();
Expand All @@ -297,38 +290,14 @@ TDNFCheckLocalPackages(
BAIL_ON_TDNF_ERROR(dwError);
}

while ((pEnt = readdir (pDir)) != NULL )
{
int nLenRpmExt = strlen(TDNF_RPM_EXT);
int nLen = strlen(pEnt->d_name);
if (nLen <= nLenRpmExt ||
strcmp(pEnt->d_name + nLen - nLenRpmExt, TDNF_RPM_EXT))
{
continue;
}
dwError = TDNFJoinPath(
&pszRPMPath,
pszLocalPath,
pEnt->d_name,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwPkgAdded = repo_add_rpm(
pCmdlineRepo,
pszRPMPath,
REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
if(!dwPkgAdded)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
queue_push2(&queueJobs, SOLVER_SOLVABLE|SOLVER_INSTALL, dwPkgAdded);
dwPackagesFound++;
TDNF_SAFE_FREE_MEMORY(pszRPMPath);
pszRPMPath = NULL;
dwError = SolvReadRpmsFromDirectory(pCmdlineRepo, pszLocalPath);
BAIL_ON_TDNF_ERROR(dwError);

FOR_REPO_SOLVABLES(pCmdlineRepo, p, s) {
queue_push2(&queueJobs, SOLVER_SOLVABLE|SOLVER_INSTALL, p);
count++;
}
repo_internalize(pCmdlineRepo);
pr_info("Found %u packages\n", dwPackagesFound);
pr_info("Found %u packages\n", count);

pSolv = solver_create(pCmdLinePool);
if(pSolv == NULL)
Expand Down Expand Up @@ -362,11 +331,6 @@ TDNFCheckLocalPackages(
solver_free(pSolv);
}
queue_free(&queueJobs);
if(pDir)
{
closedir(pDir);
}
TDNF_SAFE_FREE_MEMORY(pszRPMPath);
return dwError;

error:
Expand Down Expand Up @@ -729,10 +693,15 @@ TDNFOpenHandle(
dwError = SolvInitSack(
&pSack,
pTdnf->pConf->pszCacheDir,
pTdnf->pArgs->pszInstallRoot,
pArgs->nAllDeps);
pTdnf->pArgs->pszInstallRoot);
BAIL_ON_TDNF_ERROR(dwError);

if(!pArgs->nAllDeps)
{
dwError = SolvReadInstalledRpms(pSack->pPool->installed, pszCacheDir);
BAIL_ON_TDNF_LIBSOLV_ERROR(dwError);
}

dwError = TDNFLoadRepoData(
pTdnf,
REPOLISTFILTER_ALL,
Expand Down
13 changes: 7 additions & 6 deletions client/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,13 @@ TDNFCreateRepoFromPath(
const char *pszPath
);

uint32_t
TDNFCreateRepoFromDirectory(
PTDNF_REPO_DATA* ppRepo,
const char *pzsId,
const char *pszPath
);

uint32_t
TDNFCreateRepo(
PTDNF_REPO_DATA* ppRepo,
Expand Down Expand Up @@ -1049,12 +1056,6 @@ TDNFGetFileSize(
int *pnSize
);

uint32_t
TDNFIsDir(
const char* pszPath,
int* pnPathIsDir
);

int
TDNFIsGlob(
const char* pszString
Expand Down
36 changes: 20 additions & 16 deletions client/repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,13 @@ TDNFInitRepo(
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFGetRepoMD(pTdnf,
pRepoData,
pszRepoDataDir,
&pRepoMD);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFAllocateMemory(
1,
sizeof(SOLV_REPO_INFO_INTERNAL),
(void**)&pSolvRepoInfo);
BAIL_ON_TDNF_ERROR(dwError);

pRepo = repo_create(pPool, pRepoData->pszId);

if (!pRepo)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
Expand All @@ -80,21 +73,32 @@ TDNFInitRepo(
pSolvRepoInfo->pszRepoCacheDir = pszRepoCacheDir;
pRepo->appdata = pSolvRepoInfo;

dwError = SolvCalculateCookieForFile(pRepoMD->pszRepoMD, pSolvRepoInfo->cookie);
BAIL_ON_TDNF_ERROR(dwError);
if (pRepoData->nHasMetaData) {
dwError = TDNFGetRepoMD(pTdnf,
pRepoData,
pszRepoDataDir,
&pRepoMD);
BAIL_ON_TDNF_ERROR(dwError);

pSolvRepoInfo->nCookieSet = 1;
dwError = SolvUseMetaDataCache(pSack, pSolvRepoInfo, &nUseMetaDataCache);
BAIL_ON_TDNF_ERROR(dwError);
dwError = SolvCalculateCookieForFile(pRepoMD->pszRepoMD, pSolvRepoInfo->cookie);
BAIL_ON_TDNF_ERROR(dwError);
pSolvRepoInfo->nCookieSet = 1;

if (nUseMetaDataCache == 0)
{
dwError = TDNFInitRepoFromMetadata(pSolvRepoInfo->pRepo, pRepoData->pszId, pRepoMD);
dwError = SolvUseMetaDataCache(pSack, pSolvRepoInfo, &nUseMetaDataCache);
BAIL_ON_TDNF_ERROR(dwError);

dwError = SolvCreateMetaDataCache(pSack, pSolvRepoInfo);
if (nUseMetaDataCache == 0) {
dwError = TDNFInitRepoFromMetadata(pRepo, pRepoData->pszId, pRepoMD);
BAIL_ON_TDNF_ERROR(dwError);

dwError = SolvCreateMetaDataCache(pSack, pSolvRepoInfo);
BAIL_ON_TDNF_ERROR(dwError);
}
} else {
dwError = SolvReadRpmsFromDirectory(pRepo, pRepoData->ppszBaseUrls[0]);
BAIL_ON_TDNF_ERROR(dwError);
}

pool_createwhatprovides(pPool);

cleanup:
Expand Down
78 changes: 78 additions & 0 deletions client/repolist.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ TDNFLoadRepoData(

ppRepoNext = &((*ppRepoNext)->pNext);

TDNF_SAFE_FREE_STRINGARRAY(ppszUrlIdTuple);
ppszUrlIdTuple = NULL;
}
else if(strcmp(pSetOpt->pszOptName, "repofromdir") == 0)
{
dwError = TDNFSplitStringToArray(pSetOpt->pszOptValue, ",", &ppszUrlIdTuple);
BAIL_ON_TDNF_ERROR(dwError);
if ((ppszUrlIdTuple[0] == NULL) || ppszUrlIdTuple[1] == NULL)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
dwError = TDNFCreateRepoFromDirectory(&pReposAll,
ppszUrlIdTuple[0],
ppszUrlIdTuple[1]);
BAIL_ON_TDNF_ERROR(dwError);

TDNF_SAFE_FREE_STRINGARRAY(ppszUrlIdTuple);
ppszUrlIdTuple = NULL;
}
Expand Down Expand Up @@ -157,6 +174,7 @@ TDNFCreateCmdLineRepo(

dwError = TDNFCreateRepo(&pRepo, CMDLINE_REPO_NAME);
BAIL_ON_TDNF_ERROR(dwError);
pRepo->nHasMetaData = 0;

dwError = TDNFSafeAllocateString(CMDLINE_REPO_NAME, &pRepo->pszName);
BAIL_ON_TDNF_ERROR(dwError);
Expand All @@ -172,6 +190,64 @@ TDNFCreateCmdLineRepo(
goto cleanup;
}

uint32_t
TDNFCreateRepoFromDirectory(
PTDNF_REPO_DATA* ppRepo,
const char *pszId,
const char *pszPath
)
{
uint32_t dwError = 0;
PTDNF_REPO_DATA pRepo = NULL;
int nIsDir = 0;

if(!ppRepo || !pszId || !pszPath)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = TDNFCreateRepo(&pRepo, pszId);
BAIL_ON_TDNF_ERROR(dwError);
pRepo->nHasMetaData = 0;

/* we want it enabled, or there was no point in adding it */
pRepo->nEnabled = 1;

dwError = TDNFSafeAllocateString(pszId, &pRepo->pszName);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFIsDir(pszPath, &nIsDir);
BAIL_ON_TDNF_ERROR(dwError);

if (!nIsDir)
{
pr_err("%s is not a directory\n", pszPath);
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = TDNFAllocateMemory(sizeof(char **), 2, (void **)&pRepo->ppszBaseUrls);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFSafeAllocateString(pszPath, &pRepo->ppszBaseUrls[0]);
BAIL_ON_TDNF_ERROR(dwError);

*ppRepo = pRepo;
cleanup:
return dwError;
error:
if(ppRepo)
{
*ppRepo = NULL;
}
if(pRepo)
{
TDNFFreeReposInternal(pRepo);
}
goto cleanup;
}

uint32_t
TDNFCreateRepoFromPath(
PTDNF_REPO_DATA* ppRepo,
Expand Down Expand Up @@ -263,6 +339,7 @@ TDNFCreateRepo(
BAIL_ON_TDNF_ERROR(dwError);

pRepo->nEnabled = TDNF_REPO_DEFAULT_ENABLED;
pRepo->nHasMetaData = 1;
pRepo->nSkipIfUnavailable = TDNF_REPO_DEFAULT_SKIP;
pRepo->nGPGCheck = TDNF_REPO_DEFAULT_GPGCHECK;
pRepo->nSSLVerify = TDNF_REPO_DEFAULT_SSLVERIFY;
Expand Down Expand Up @@ -393,6 +470,7 @@ TDNFLoadReposFromFile(
sizeof(TDNF_REPO_DATA),
(void**)&pRepo);
BAIL_ON_TDNF_ERROR(dwError);
pRepo->nHasMetaData = 1;

dwError = TDNFAllocateString(pszRepo, &pRepo->pszId);
BAIL_ON_TDNF_ERROR(dwError);
Expand Down
36 changes: 0 additions & 36 deletions client/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,6 @@ TDNFGetFileSize(
goto cleanup;
}

uint32_t
TDNFIsDir(
const char* pszPath,
int* pnPathIsDir
)
{
uint32_t dwError = 0;
int nPathIsDir = 0;
struct stat stStat = {0};

if(!pnPathIsDir || IsNullOrEmptyString(pszPath))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

if(stat(pszPath, &stStat))
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

nPathIsDir = S_ISDIR(stStat.st_mode);

*pnPathIsDir = nPathIsDir;
cleanup:
return dwError;

error:
if(pnPathIsDir)
{
*pnPathIsDir = 0;
}
goto cleanup;
}

/* update time if file exists, create if not */
uint32_t
TDNFTouchFile(
Expand Down
6 changes: 6 additions & 0 deletions common/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ TDNFReadFileToStringArray(
char ***pppszArray
);

uint32_t
TDNFIsDir(
const char* pszPath,
int* pnPathIsDir
);

//setopt.c
uint32_t
AddSetOpt(
Expand Down
Loading