Skip to content

Commit

Permalink
Don't create AnonymousUniqueId in chroot (bsc#1024741)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandres committed Feb 16, 2017
1 parent f28ad4d commit 34ba8f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
14 changes: 11 additions & 3 deletions tests/zypp/Target_test.cc
@@ -1,5 +1,5 @@

#include <iostream>
#include <fstream>
#include <list>
#include <string>

Expand Down Expand Up @@ -34,9 +34,17 @@ BOOST_AUTO_TEST_CASE(target_test)

z->initializeTarget( tmp.path() );

BOOST_CHECK( ! z->target()->anonymousUniqueId().empty() );
// bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
BOOST_CHECK( ! PathInfo( tmp.path() / "/var/lib/zypp/AnonymousUniqueId").isExist() );
// create an artificial one
{
Pathname f( tmp.path() / "/var/lib/zypp" );
filesystem::assert_dir( f );
std::ofstream o( (f/"AnonymousUniqueId").c_str() );
o << "AnonymousUniqueId";
}
BOOST_CHECK( PathInfo( tmp.path() / "/var/lib/zypp/AnonymousUniqueId").isExist() );
BOOST_CHECK( PathInfo( tmp.path() / "/var/lib/zypp/AnonymousUniqueId").size() > 0 );
BOOST_CHECK_EQUAL( z->target()->anonymousUniqueId(), "AnonymousUniqueId" );

// now check the base product
BOOST_CHECK_EQUAL( z->target()->targetDistribution(), "sle-10-i586");
Expand Down
24 changes: 20 additions & 4 deletions zypp/target/TargetImpl.cc
Expand Up @@ -751,9 +751,11 @@ namespace zypp

void TargetImpl::createAnonymousId() const
{
// bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
if ( root() != "/" )
return;

// create the anonymous unique id
// this value is used for statistics
// Create the anonymous unique id, used for download statistics
Pathname idpath( home() / "AnonymousUniqueId");

try
Expand Down Expand Up @@ -1830,15 +1832,29 @@ namespace zypp
}

///////////////////////////////////////////////////////////////////
namespace
{
std::string guessAnonymousUniqueId( const Pathname & root_r )
{
// bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
std::string ret( firstNonEmptyLineIn( root_r / "/var/lib/zypp/AnonymousUniqueId" ) );
if ( ret.empty() && root_r != "/" )
{
// if it has nonoe, use the outer systems one
ret = firstNonEmptyLineIn( "/var/lib/zypp/AnonymousUniqueId" );
}
return ret;
}
}

std::string TargetImpl::anonymousUniqueId() const
{
return firstNonEmptyLineIn( home() / "AnonymousUniqueId" );
return guessAnonymousUniqueId( root() );
}
// static version:
std::string TargetImpl::anonymousUniqueId( const Pathname & root_r )
{
return firstNonEmptyLineIn( staticGuessRoot(root_r) / "/var/lib/zypp/AnonymousUniqueId" );
return guessAnonymousUniqueId( staticGuessRoot(root_r) );
}

///////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 34ba8f1

Please sign in to comment.