This allows e.g the media backend to access those data even if the target is not initialized when downloading.
Date Target::timestamp() const
{ return _pimpl->timestamp(); }
- std::string Target::distributionFlavor() const
- { return _pimpl->distributionFlavor(); }
+ Product::constPtr Target::baseProduct() const
+ { return _pimpl->baseProduct(); }
std::string Target::targetDistribution() const
{ return _pimpl->targetDistribution(); }
+ std::string Target::targetDistribution( const Pathname & root_r )
+ { return target::TargetImpl::targetDistribution( root_r ); }
std::string Target::targetDistributionRelease() const
{ return _pimpl->targetDistributionRelease(); }
-
- std::string Target::anonymousUniqueId() const
- { return _pimpl->anonymousUniqueId(); }
+ std::string Target::targetDistributionRelease( const Pathname & root_r )
+ { return target::TargetImpl::targetDistributionRelease( root_r ); }
std::string Target::distributionVersion() const
{ return _pimpl->distributionVersion(); }
+ std::string Target::distributionVersion( const Pathname & root_r )
+ { return target::TargetImpl::distributionVersion( root_r ); }
- Product::constPtr Target::baseProduct() const
- { return _pimpl->baseProduct(); }
+ std::string Target::distributionFlavor() const
+ { return _pimpl->distributionFlavor(); }
+ std::string Target::distributionFlavor( const Pathname & root_r )
+ { return target::TargetImpl::distributionFlavor( root_r ); }
+ std::string Target::anonymousUniqueId() const
+ { return _pimpl->anonymousUniqueId(); }
+ std::string Target::anonymousUniqueId( const Pathname & root_r )
+ { return target::TargetImpl::anonymousUniqueId( root_r ); }
/////////////////////////////////////////////////////////////////
} // namespace zypp
*/
Product::constPtr baseProduct() const;
- /** \name Base product and registration. */
+ public:
+ /** \name Base product and registration.
+ *
+ * Static methods herein allow to retrieve the values without explicitly
+ * initializing the \ref Target. They take a targets root directory as
+ * argument. If an empty \ref Pathname is passed, an already existing
+ * Targets root is used, otherwise \c "\" is assumed.
+ */
//@{
/** This is \c register.target attribute of the installed base product.
* Used for registration and \ref Service refresh.
*/
std::string targetDistribution() const;
+ /** \overload */
+ static std::string targetDistribution( const Pathname & root_r );
/** This is \c register.release attribute of the installed base product.
* Used for registration.
*/
std::string targetDistributionRelease() const;
- //@}
+ /** \overload */
+ static std::string targetDistributionRelease( const Pathname & root_r );
/** This is \c version attribute of the installed base product.
* For example http://download.opensue.org/update/11.0
* The 11.0 corresponds to the base product version.
*/
std::string distributionVersion() const;
- //@}
-
+ /** \overload */
+ static std::string distributionVersion( const Pathname & root_r );
/**
- * This is \flavor attribute of the installed base product
+ * This is \c flavor attribute of the installed base product
* but does not require the target to be loaded as it remembers
* the last used one. It can be empty is the target has never
* been loaded, as the value is not present in the system
* but computer from a package provides
*/
std::string distributionFlavor() const;
+ /** \overload */
+ static std::string distributionFlavor( const Pathname & root_r );
/**
* anonymous unique id
*
*/
std::string anonymousUniqueId() const;
+ /** \overload */
+ static std::string anonymousUniqueId( const Pathname & root_r );
+ //@}
public:
/** Ctor. If \c doRebuild_r is \c true, an already existing
return 0L;
}
+ ///////////////////////////////////////////////////////////////////
+
namespace
{
parser::ProductFileData baseproductdata( const Pathname & root_r )
return parser::ProductFileData();
}
+ inline Pathname staticGuessRoot( const Pathname & root_r )
+ {
+ if ( root_r.empty() )
+ {
+ // empty root: use existing Target or assume "/"
+ Pathname ret ( ZConfig::instance().systemRoot() );
+ if ( ret.empty() )
+ return Pathname("/");
+ return ret;
+ }
+ return root_r;
+ }
+
+ inline std::string firstNonEmptyLineIn( const Pathname & file_r )
+ {
+ std::ifstream idfile( file_r.c_str() );
+ for( iostr::EachLine in( idfile ); in; in.next() )
+ {
+ std::string line( str::trim( *in ) );
+ if ( ! line.empty() )
+ return line;
+ }
+ return std::string();
+ }
}
std::string TargetImpl::targetDistribution() const
{ return baseproductdata( _root ).registerTarget(); }
+ // static version:
+ std::string TargetImpl::targetDistribution( const Pathname & root_r )
+ { return baseproductdata( staticGuessRoot(root_r) ).registerTarget(); }
+
std::string TargetImpl::targetDistributionRelease() const
{ return baseproductdata( _root ).registerRelease(); }
+ // static version:
+ std::string TargetImpl::targetDistributionRelease( const Pathname & root_r )
+ { return baseproductdata( staticGuessRoot(root_r) ).registerRelease();}
+
std::string TargetImpl::distributionVersion() const
{
}
return _distributionVersion;
}
+ // static version: (no fallback to init and read rpm db here)
+ std::string TargetImpl::distributionVersion( const Pathname & root_r )
+ { return baseproductdata( staticGuessRoot(root_r) ).edition().version(); }
+
std::string TargetImpl::distributionFlavor() const
{
- std::ifstream idfile( ( home() / "LastDistributionFlavor" ).c_str() );
- for( iostr::EachLine in( idfile ); in; in.next() )
- {
- std::string line( str::trim( *in ) );
- if ( ! line.empty() )
- return line;
- }
- return std::string();
+ return firstNonEmptyLineIn( home() / "LastDistributionFlavor" );
+ }
+ // static version:
+ std::string TargetImpl::distributionFlavor( const Pathname & root_r )
+ {
+ return firstNonEmptyLineIn( staticGuessRoot(root_r) / "/var/lib/zypp/LastDistributionFlavor" );
}
///////////////////////////////////////////////////////////////////
std::string TargetImpl::anonymousUniqueId() const
{
- std::ifstream idfile( ( home() / "AnonymousUniqueId" ).c_str() );
- for( iostr::EachLine in( idfile ); in; in.next() )
- {
- std::string line( str::trim( *in ) );
- if ( ! line.empty() )
- return line;
- }
- return std::string();
+ return firstNonEmptyLineIn( home() / "AnonymousUniqueId" );
+ }
+ // static version:
+ std::string TargetImpl::anonymousUniqueId( const Pathname & root_r )
+ {
+ return firstNonEmptyLineIn( staticGuessRoot(root_r) / "/var/lib/zypp/AnonymousUniqueId" );
}
///////////////////////////////////////////////////////////////////
void buildCache();
//@}
- std::string anonymousUniqueId() const;
-
public:
/** The root set for this target */
/** \copydoc Target::baseProduct() */
Product::constPtr baseProduct() const;
- /** \copydoc Target::release() */
- std::string release() const;
/** \copydoc Target::targetDistribution() */
std::string targetDistribution() const;
+ /** \overload */
+ static std::string targetDistribution( const Pathname & root_r );
/** \copydoc Target::targetDistributionRelease()*/
std::string targetDistributionRelease() const;
+ /** \overload */
+ static std::string targetDistributionRelease( const Pathname & root_r );
/** \copydoc Target::distributionVersion()*/
std::string distributionVersion() const;
+ /** \overload */
+ static std::string distributionVersion( const Pathname & root_r );
/** \copydoc Target::distributionFlavor() */
std::string distributionFlavor() const;
+ /** \overload */
+ static std::string distributionFlavor( const Pathname & root_r );
+
+ /** \copydoc Target::anonymousUniqueId() */
+ std::string anonymousUniqueId() const;
+ /** \overload */
+ static std::string anonymousUniqueId( const Pathname & root_r );
private:
/** Commit ordered changes (internal helper) */