12 #include <solv/solvversion.h> 33 namespace zypp_readonly_hack {
43 inline void cleanupNonRepoMetadataFolders(
const Pathname & cachePath_r,
44 const Pathname & defaultCachePath_r,
45 const std::list<std::string> & repoEscAliases_r )
47 if ( cachePath_r != defaultCachePath_r )
50 std::list<std::string> entries;
54 std::set<std::string> oldfiles;
55 set_difference( entries.begin(), entries.end(), repoEscAliases_r.begin(), repoEscAliases_r.end(),
56 std::inserter( oldfiles, oldfiles.end() ) );
62 for (
const std::string & old : oldfiles )
66 pi( cachePath_r/old );
78 std::string filename( alias_r );
83 MIL <<
"generating filename for " << stem_r <<
" [" << alias_r <<
"] : '" << filename <<
"'" << endl;
96 <<
"' distribution (current distro is '" 102 repos.push_back(repo);
108 MIL <<
"repo file: " << file << endl;
111 return std::move(collector.
repos);
116 MIL <<
"directory " << dir << endl;
117 std::list<RepoInfo> repos;
118 bool nonroot( geteuid() != 0 );
119 if ( nonroot && !
PathInfo(dir).userMayRX() )
125 std::list<Pathname> entries;
132 str::regex allowedRepoExt(
"^\\.repo(_[0-9]+)?$");
133 for ( std::list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
144 repos.insert( repos.end(), tmp.begin(), tmp.end() );
163 : _options(
std::move(opt))
186 switch ( repokind.
toEnum() )
189 status =
RepoStatus( productdatapath/
"repodata/repomd.xml");
191 status = status &&
RepoStatus( mediarootpath/
"media.1/media" );
195 status =
RepoStatus( productdatapath/
"content" ) &&
RepoStatus( mediarootpath/
"media.1/media" );
212 if ( ! status.
empty() )
226 progress.
sendTo(progressfnc);
235 progress.
sendTo(progressfnc);
252 MIL <<
"going to probe the cached repo at " << path_r << endl;
256 if (
PathInfo(path_r/
"/repodata/repomd.xml").isFile() )
258 else if (
PathInfo(path_r/
"/content").isFile() )
260 else if (
PathInfo(path_r).isDir() )
263 MIL <<
"Probed cached type " << ret <<
" at " << path_r << endl;
269 MIL <<
"Going to clean up garbage in cache dirs" << endl;
272 progress.
sendTo(progressrcv);
275 std::list<Pathname> cachedirs;
280 for_( dir, cachedirs.begin(), cachedirs.end() )
284 std::list<Pathname> entries;
289 unsigned sdircount = entries.size();
290 unsigned sdircurrent = 1;
291 for_( subdir, entries.begin(), entries.end() )
296 if ( subdir->basename() == r->escaped_alias() )
297 { found =
true;
break; }
302 progress.
set( progress.
val() + sdircurrent * 100 / sdircount );
307 progress.
set( progress.
val() + 100 );
315 progress.
sendTo(progressrcv);
318 MIL <<
"Removing raw metadata cache for " << info.
alias() << endl;
329 if ( !
PathInfo(solvfile).isExist() )
338 if ( toolversion != LIBSOLV_TOOLVERSION ) {
355 MIL <<
"Saving repo in " << repofile << endl;
357 std::ofstream file(repofile.
c_str());
364 tosave.dumpAsIniOn(file);
365 tosave.setFilepath(repofile);
371 RepoInfo & oinfo( const_cast<RepoInfo &>(info) );
391 MIL <<
"Going to delete repo " << info.
alias() << endl;
398 if ( (!info.
alias().empty()) && ( info.
alias() != (*it).alias() ) )
414 if ( filerepos.size() == 0
415 ||(filerepos.size() == 1 && filerepos.front().alias() == todelete.
alias() ) )
419 if ( ! ( ret == 0 || ret == ENOENT ) )
424 MIL << todelete.
alias() <<
" successfully deleted." << endl;
442 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
443 fit != filerepos.end();
446 if ( (*fit).alias() != todelete.
alias() )
447 (*fit).dumpAsIniOn(file);
461 MIL << todelete.
alias() <<
" successfully deleted." << endl;
505 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
506 fit != filerepos.end();
511 if ( (*fit).alias() != toedit.
alias() )
512 (*fit).dumpAsIniOn(file);
531 RepoInfo & oinfo( const_cast<RepoInfo &>(newinfo_r) );
541 MIL <<
"repo " << alias <<
" modified" << endl;
548 if ( it !=
repos().end() )
560 for_( urlit, (*it).baseUrlsBegin(), (*it).baseUrlsEnd() )
562 if ( (*urlit).asString(urlview) == url.
asString(urlview) )
588 MIL <<
"added service " << toSave.
alias() << endl;
595 MIL <<
"Going to delete service " << alias << endl;
600 if( location.
empty() )
609 if ( tmpSet.size() == 1 )
616 MIL << alias <<
" successfully deleted." << endl;
622 std::ofstream file(location.
c_str());
629 for_(it, tmpSet.begin(), tmpSet.end())
631 if( it->alias() != alias )
632 it->dumpAsIniOn(file);
635 MIL << alias <<
" successfully deleted from file " << location << endl;
649 MIL <<
"Going to modify service " << oldAlias << endl;
663 if( location.
empty() )
673 std::ofstream file(location.
c_str());
674 for_(it, tmpSet.begin(), tmpSet.end())
676 if( *it != oldAlias )
677 it->dumpAsIniOn(file);
690 if ( oldAlias != service.
alias()
693 std::vector<RepoInfo> toModify;
695 for_( it, toModify.begin(), toModify.end() )
702 const auto & last = service.
repoStates().find( it->alias() );
704 it->setEnabled( last->second.enabled );
707 it->setEnabled(
false );
710 if ( oldAlias != service.
alias() )
711 it->setService(service.
alias());
728 MIL <<
"saving service in " << servfile << endl;
730 std::ofstream file( servfile.
c_str() );
737 MIL <<
"done" << endl;
756 const std::string & basefilename )
const 758 std::string final_filename = basefilename;
760 while (
PathInfo(dir + final_filename).isExist() )
765 return dir +
Pathname(final_filename);
781 switch ( repokind.
toEnum() )
784 p =
Pathname(productdatapath +
"/repodata/repomd.xml");
788 p =
Pathname(productdatapath +
"/content");
792 p =
Pathname(productdatapath +
"/cookie");
812 std::list<Pathname> entries;
822 for_(it, entries.begin(), entries.end() )
838 inline void cleanupNonRepoMetadtaFolders(
const Pathname & cachePath_r,
839 const Pathname & defaultCachePath_r,
840 const std::list<std::string> & repoEscAliases_r )
845 if ( cachePath_r != defaultCachePath_r )
848 std::list<std::string> entries;
852 std::set<std::string> oldfiles;
853 set_difference( entries.begin(), entries.end(), repoEscAliases_r.begin(), repoEscAliases_r.end(),
854 std::inserter( oldfiles, oldfiles.end() ) );
860 for (
const std::string & old : oldfiles )
864 pi( cachePath_r/old );
876 MIL <<
"start construct known repos" << endl;
880 std::list<std::string> repoEscAliases;
881 std::list<RepoInfo> orphanedRepos;
892 const std::string & serviceAlias( repoInfo.service() );
893 if ( ! ( serviceAlias.empty() ||
hasService( serviceAlias ) ) )
895 WAR <<
"Schedule orphaned service repo for deletion: " << repoInfo << endl;
896 orphanedRepos.push_back( repoInfo );
900 repoEscAliases.push_back(repoInfo.escaped_alias());
904 if ( ! orphanedRepos.empty() )
906 for (
const auto & repoInfo : orphanedRepos )
908 MIL <<
"Delete orphaned service repo " << repoInfo.alias() << endl;
914 % repoInfo.alias() );
932 repoEscAliases.sort();
946 MIL <<
"end construct known repos" << endl;
951 if ( info.
alias().empty() )
955 if ( info.
alias()[0] ==
'.')
957 info,
_(
"Repository alias cannot start with dot.")));
std::string asString(const Patch::Category &obj)
Pathname filepath() const
File where this repo was read from.
static const ValueType day
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
void setBaseUrl(Url url)
Clears current base URL list and adds url.
std::ostream & dumpAsIniOn(std::ostream &str) const override
Writes ServiceInfo to stream in ".service" format.
thrown when it was impossible to match a repository
Pathname builtinRepoPackagesPath() const
The builtin config file value.
bool empty() const
Whether the status is empty (empty checksum)
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
Pathname solv_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the solv cache path for a repository.
Pathname repoRawCachePath
const Pathname & path() const
Return current Pathname.
Read service data from a .service file.
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
virtual ~RepoManagerBaseImpl()
std::string generateFilename(const RepoInfo &info) const
void removeService(const std::string &alias)
static ZConfig & instance()
Singleton ctor.
std::list< RepoInfo > repositories_in_file(const Pathname &file)
Reads RepoInfo's from a repo file.
bool collect(const RepoInfo &repo)
bool hasRepo(const std::string &alias) const
Service plugin is immutable.
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Pathname builtinRepoMetadataPath() const
The builtin config file value.
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
void loadFromCache(const RepoInfo &info, OPT_PROGRESS)
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
const char * c_str() const
String representation.
void setAlias(const std::string &alias)
set the repository alias
bool toMax()
Set counter value to current max value (unless no range).
void setFilepath(const Pathname &filename)
set the path to the .repo file
What is known about a repository.
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
Pathname packagescache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the packages cache path for a repository.
Pathname knownServicesPath
void reposErase(const std::string &alias_r)
Remove a Repository named alias_r.
Service already exists and some unique attribute can't be duplicated.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
void removeRepositoryImpl(const RepoInfo &info, OPT_PROGRESS)
Url::asString() view options.
Pathname rawcache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the raw cache path for a repository, this is usually /var/cache/zypp/alias.
Pathname repoSolvCachePath
const RepoSet & repos() const
bool baseUrlsEmpty() const
whether repository urls are available
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Progress callback from another progress.
bool hasService(const std::string &alias) const
bool empty() const
Test for an empty path.
bool toMin()
Set counter value to current min value.
void cleanPackages(const RepoInfo &info, OPT_PROGRESS, bool isAutoClean=false)
std::string asString() const
Returns a default string representation of the Url object.
static RepoStatus fromCookieFileUseMtime(const Pathname &path)
Reads the status from a cookie file but uses the files mtime.
static Pool instance()
Singleton ctor.
void addProbedRepository(const RepoInfo &info, repo::RepoType probedType)
Pathname rootDir
remembers root_r value for later use
void removeRepository(const RepoInfo &repo)
Log recently removed repository.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Lightweight repository attribute value lookup.
Pathname generateNonExistingName(const Pathname &dir, const std::string &basefilename) const
Generate a non existing filename in a directory, using a base name.
int unlink(const Pathname &path)
Like 'unlink'.
thrown when it was impossible to determine one url for this repo.
void assert_alias(const RepoInfo &info)
Iterator findAlias(const std::string &alias_r, Iterator begin_r, Iterator end_r)
Find alias_r in repo/service container.
const std::string & asString() const
String representation.
std::string alias() const
unique identifier for this source.
bool isExist() const
Return whether valid stat info exists.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
static const SolvAttr repositoryToolVersion
Pathname rawproductdata_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the raw product metadata path for a repository, this is inside the raw cache dir...
Pathname dirname() const
Return all but the last component od this path.
static Pathname assertprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r prefixed with root_r, unless it is already prefixed.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
RepoManagerOptions _options
Maintain [min,max] and counter (value) for progress counting.
void cleanMetadata(const RepoInfo &info, OPT_PROGRESS)
void addRepository(const RepoInfo &repo)
Log a newly added repository.
ServiceInfo getService(const std::string &alias) const
Writing the zypp history fileReference counted signleton for writhing the zypp history file...
void addService(const ServiceInfo &service)
Read repository data from a .repo file.
static const ServiceType PLUGIN
Plugin services are scripts installed on your system that provide the package manager with repositori...
Base Exception for service handling.
void saveService(ServiceInfo &service) const
bool requireStatusWithMediaFile() const
Returns true if this repository requires the media.1/media file to be included in the metadata status...
std::string numstring(char n, int w=0)
static const RepoType NONE
void cleanCacheDirGarbage(OPT_PROGRESS)
int touch(const Pathname &path)
Change file's modification and access times.
void init_knownServices()
Url url() const
The service url.
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
static const RepoType RPMMD
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
Pathname builtinRepoSolvfilesPath() const
The builtin config file value.
Simple callback to collect the results.
virtual void removeRepository(const RepoInfo &info, OPT_PROGRESS)=0
static const RepoType YAST2
thrown when it was impossible to determine an alias for this repo.
static repo::RepoType probeCache(const Pathname &path_r)
Probe Metadata in a local cache directory.
std::string filenameFromAlias(const std::string &alias_r, const std::string &stem_r)
Generate a related filename from a repo/service infos alias.
static void touchIndexFile(const RepoInfo &info, const RepoManagerOptions &options)
const RepoStates & repoStates() const
Access the remembered repository states.
Base class for Exception.
void assert_urls(const RepoInfo &info)
std::ostream & dumpAsIniOn(std::ostream &str) const override
Write this RepoInfo object into str in a .repo file format.
void cleanCache(const RepoInfo &info, OPT_PROGRESS)
Exception for repository handling.
static Date now()
Return the current time.
void modifyService(const std::string &oldAlias, const ServiceInfo &newService)
The repository cache is not built yet so you can't create the repostories from the cache...
RepoConstIterator repoBegin() const
void eraseFromPool()
Remove this Repository from its Pool.
std::string targetDistribution() const
Distribution for which is this repository meant.
Pathname repoPackagesCachePath
Functor collecting ServiceInfos into a ServiceSet.
std::set< ServiceInfo > ServiceSet
ServiceInfo typedefs.
RepoSet::const_iterator RepoConstIterator
Wrapper class for ::stat/::lstat.
void getRepositoriesInService(const std::string &alias, OutputIterator out) const
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
RepoManagerBaseImpl(RepoManagerOptions &&opt)
Thrown when the repo alias is found to be invalid.
static const RepoType RPMPLAINDIR
static const std::string & systemRepoAlias()
Reserved system repository alias .
Track changing files or directories.
Repository already exists and some unique attribute can't be duplicated.
bool set(value_type val_r)
Set new counter value.
std::list< RepoInfo > repositories_in_dir(const Pathname &dir)
List of RepoInfo's from a directory.
void modifyRepository(const RepoInfo &oldrepo, const RepoInfo &newrepo)
Log certain modifications to a repository.
Repository addRepoSolv(const Pathname &file_r, const std::string &name_r)
Load Solvables from a solv-file into a Repository named name_r.
void name(const std::string &name_r)
Set counter name.
Easy-to use interface to the ZYPP dependency resolver.
void init_knownRepositories()
static RepoStatus metadataStatus(const RepoInfo &info, const RepoManagerOptions &options)
RepoConstIterator repoEnd() const
repo::ServiceType type() const
Service type.
std::string label() const
Label for use in messages for the user interface.
url_set baseUrls() const
The complete set of repository urls.
repo::RepoType type() const
Type of repository,.
bool isCached(const RepoInfo &info) const
RepoInfo getRepositoryInfo(const std::string &alias)
bool autoPruneInDir(const Pathname &path_r)
bsc#1204956: Tweak to prevent auto pruning package caches.
Repository type enumeration.
void modifyRepository(const std::string &alias, const RepoInfo &newinfo_r, OPT_PROGRESS)