5 #include <zypp/base/LogControl.h>
6 #include <zypp/base/LogTools.h>
7 #include <zypp/base/String.h>
8 #include <zypp/base/SerialNumber.h>
9 #include <zypp/ExternalProgram.h>
10 #include <zypp/PathInfo.h>
11 #include <zypp/TmpPath.h>
12 #include <zypp/ResPoolProxy.h>
13 #include <zypp/repo/PackageProvider.h>
14 #include <zypp/media/MediaManager.h>
15 #include <zypp/MediaSetAccess.h>
16 #include <zypp/Fetcher.h>
18 static const Pathname sysRoot( "/" );
21 using namespace zypp::ui;
24 #include <zypp/ZYppCallbacks.h>
26 struct DownloadProgressReceive : public callback::ReceiveReport<media::DownloadProgressReport>
28 DownloadProgressReceive()
32 ABORT, // abort and return error
34 IGNORE // ignore the failure
39 NOT_FOUND, // the requested Url was not found
41 ACCESS_DENIED, // user authent. failed while accessing restricted file
45 virtual void start( const Url & file, Pathname localfile )
47 USR << "DP +++ " << file << endl;
51 virtual bool progress(int value, const Url &file, double dbps_avg = -1, double dbps_current = -1)
53 if ( abs(value-lp) >= 20 || value == 100 && lp != 100 )
55 USR << "DP " << file << " " << value << "%" << endl;
62 virtual Action problem( const Url &file , Error error , const std::string &description )
64 USR << "DP !!! " << file << " (" << error << ")" << endl;
69 virtual void finish( const Url &file , Error error , const std::string &reason )
71 USR << "DP --- " << file << " (" << error << ")" << endl;
77 ////////////////////////////////////////////////////////////////////
79 //////////////////////////////////////////////////////////////////
81 struct DownloadResolvableReceive : public callback::ReceiveReport<repo::DownloadResolvableReport>
83 DownloadResolvableReceive()
87 ABORT, // abort and return error
89 IGNORE, // ignore this resolvable but continue
94 NOT_FOUND, // the requested Url was not found
96 INVALID // the downloaded file is invalid
99 virtual void start( Resolvable::constPtr resolvable_ptr, const Url &url )
101 USR << "+++ " << resolvable_ptr << endl;
105 // Dowmload delta rpm:
106 // - path below url reported on start()
107 // - expected download size (0 if unknown)
108 // - download is interruptable
109 // - problems are just informal
110 virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
112 USR << __PRETTY_FUNCTION__ << endl;
115 virtual bool progressDeltaDownload( int /*value*/ )
117 USR << __PRETTY_FUNCTION__ << endl;
121 virtual void problemDeltaDownload( const std::string &/*description*/ )
123 USR << __PRETTY_FUNCTION__ << endl;
126 virtual void finishDeltaDownload()
128 USR << __PRETTY_FUNCTION__ << endl;
132 // - local path of downloaded delta
133 // - aplpy is not interruptable
134 // - problems are just informal
135 virtual void startDeltaApply( const Pathname & /*filename*/ )
137 USR << __PRETTY_FUNCTION__ << endl;
140 virtual void progressDeltaApply( int /*value*/ )
142 USR << __PRETTY_FUNCTION__ << endl;
145 virtual void problemDeltaApply( const std::string &/*description*/ )
147 USR << __PRETTY_FUNCTION__ << endl;
150 virtual void finishDeltaApply()
152 USR << __PRETTY_FUNCTION__ << endl;
155 // return false if the download should be aborted right now
156 virtual bool progress(int value, Resolvable::constPtr resolvable_ptr)
158 if ( 1 || abs(value-lp) >= 20 || value == 100 && lp != 100 )
160 USR << resolvable_ptr << " " << value << "%" << endl;
166 virtual Action problem( Resolvable::constPtr resolvable_ptr , Error error , const std::string &/*description*/ )
168 USR << "!!! " << resolvable_ptr << " (" << error << ")" << endl;
172 virtual void finish(Resolvable::constPtr resolvable_ptr , Error error , const std::string &/*reason*/ )
174 USR << "--- " << resolvable_ptr << " (" << error << ")" << endl;
181 bool queryInstalledEditionHelper( const std::string & name_r,
182 const Edition & ed_r,
183 const Arch & arch_r )
185 if ( ed_r == Edition::noedition )
187 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
189 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
195 ManagedFile repoProvidePackage( const PoolItem & pi )
197 ResPool _pool( getZYpp()->pool() );
198 repo::RepoMediaAccess _access;
200 // Redirect PackageProvider queries for installed editions
201 // (in case of patch/delta rpm processing) to rpmDb.
202 repo::PackageProviderPolicy packageProviderPolicy;
203 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
205 Package::constPtr p = asKind<Package>( pi.resolvable() );
207 // Build a repository list for repos
208 // contributing to the pool
209 repo::DeltaCandidates deltas;//( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(), _pool.knownRepositoriesEnd() ) );
211 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
213 return pkgProvider.providePackage();
216 /******************************************************************
218 ** FUNCTION NAME : main
219 ** FUNCTION TYPE : int
221 int main( int argc, char * argv[] )
225 zypp::base::LogControl::instance().logToStdErr();
226 INT << "===[START]==========================================" << endl;
227 ::unsetenv( "ZYPP_CONF" );
230 DownloadProgressReceive _dpr;
231 DownloadResolvableReceive _drr;
233 TestSetup::LoadSystemAt( sysRoot );
234 ///////////////////////////////////////////////////////////////////
235 ResPool pool( ResPool::instance() );
236 sat::Pool satpool( sat::Pool::instance() );
237 ///////////////////////////////////////////////////////////////////
238 dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() ) << endl;
239 USR << "pool: " << pool << endl;
242 PoolItem pi( getPi<Package>( "CDT", "amarok", Edition(), Arch_empty ) );
244 ManagedFile f( repoProvidePackage( pi ) );
248 Url url("cd:///?devices=/dev/sr0");
249 Pathname path(url.getPathName());
250 url.setPathName ("/");
251 MediaSetAccess access(url);
252 Pathname local = access.provideFile(path);
253 SEC << local << endl;
256 Url url("http://download.opensuse.org/debug/distribution/11.4/repo/oss/content.asc");
257 url.setPathName ("/");
258 MediaSetAccess access(url);
262 fch.setOptions(zypp::Fetcher::AutoAddIndexes);
264 // path - add "/" to the beginning if it's missing there
265 std::string media_path("/debug/distribution/11.4/repo/oss/content.ascx");
266 zypp::OnMediaLocation mloc(media_path, 1);
267 mloc.setOptional(true);
269 zypp::filesystem::TmpDir tmpdir( zypp::filesystem::TmpDir::defaultLocation() );
271 fch.start(tmpdir.path(), access);
277 // ExternalProgram("find /tmp/var") >> DBG;
280 INT << "===[END]============================================" << endl;
281 zypp::base::LogControl::instance().logNothing();