/
ZYppCallbacks.h
720 lines (607 loc) · 20 KB
/
ZYppCallbacks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
/*---------------------------------------------------------------------\
| ____ _ __ __ ___ |
| |__ / \ / / . \ . \ |
| / / \ V /| _/ _/ |
| / /__ | | | | | | |
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
/** \file zypp/ZYppCallbacks.h
*
*/
#ifndef ZYPP_ZYPPCALLBACKS_H
#define ZYPP_ZYPPCALLBACKS_H
#include "zypp/Callback.h"
#include "zypp/Resolvable.h"
#include "zypp/RepoInfo.h"
#include "zypp/Pathname.h"
#include "zypp/Package.h"
#include "zypp/Patch.h"
#include "zypp/Url.h"
#include "zypp/ProgressData.h"
#include "zypp/media/MediaUserAuth.h"
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
struct ProgressReport : public callback::ReportBase
{
virtual void start( const ProgressData &/*task*/ )
{}
virtual bool progress( const ProgressData &/*task*/ )
{ return true; }
// virtual Action problem(
// Repo /*source*/
// , Error /*error*/
// , const std::string &/*description*/ )
// { return ABORT; }
virtual void finish( const ProgressData &/*task*/ )
{}
};
struct ProgressReportAdaptor
{
ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
callback::SendReport<ProgressReport> &report )
: _fnc(fnc)
, _report(report)
, _first(true)
{
}
bool operator()( const ProgressData &progress )
{
if ( _first )
{
_report->start(progress);
_first = false;
}
_report->progress(progress);
bool value = true;
if ( _fnc )
value = _fnc(progress);
if ( progress.finalReport() )
{
_report->finish(progress);
}
return value;
}
ProgressData::ReceiverFnc _fnc;
callback::SendReport<ProgressReport> &_report;
bool _first;
};
////////////////////////////////////////////////////////////////////////////
namespace repo
{
// progress for downloading a resolvable
struct DownloadResolvableReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE, // ignore this resolvable but continue
};
enum Error {
NO_ERROR,
NOT_FOUND, // the requested Url was not found
IO, // IO error
INVALID // the downloaded file is invalid
};
virtual void start(
Resolvable::constPtr /*resolvable_ptr*/
, const Url &/*url*/
) {}
// Dowmload delta rpm:
// - path below url reported on start()
// - expected download size (0 if unknown)
// - download is interruptable
// - problems are just informal
virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
{}
virtual bool progressDeltaDownload( int /*value*/ )
{ return true; }
virtual void problemDeltaDownload( const std::string &/*description*/ )
{}
virtual void finishDeltaDownload()
{}
// Apply delta rpm:
// - local path of downloaded delta
// - aplpy is not interruptable
// - problems are just informal
virtual void startDeltaApply( const Pathname & /*filename*/ )
{}
virtual void progressDeltaApply( int /*value*/ )
{}
virtual void problemDeltaApply( const std::string &/*description*/ )
{}
virtual void finishDeltaApply()
{}
// Dowmload patch rpm:
// - path below url reported on start()
// - expected download size (0 if unknown)
// - download is interruptable
virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
{}
virtual bool progressPatchDownload( int /*value*/ )
{ return true; }
virtual void problemPatchDownload( const std::string &/*description*/ )
{}
virtual void finishPatchDownload()
{}
// return false if the download should be aborted right now
virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
{ return true; }
virtual Action problem(
Resolvable::constPtr /*resolvable_ptr*/
, Error /*error*/
, const std::string &/*description*/
) { return ABORT; }
virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
, Error /*error*/
, const std::string &/*reason*/
) {}
};
// progress for probing a source
struct ProbeRepoReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY // retry
};
enum Error {
NO_ERROR,
NOT_FOUND, // the requested Url was not found
IO, // IO error
INVALID, // th source is invalid
UNKNOWN
};
virtual void start(const Url &/*url*/) {}
virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
virtual bool progress(const Url &/*url*/, int /*value*/)
{ return true; }
virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
};
struct RepoCreateReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE // skip refresh, ignore failed refresh
};
enum Error {
NO_ERROR,
NOT_FOUND, // the requested Url was not found
IO, // IO error
REJECTED,
INVALID, // th source is invali
UNKNOWN
};
virtual void start( const zypp::Url &/*url*/ ) {}
virtual bool progress( int /*value*/ )
{ return true; }
virtual Action problem(
const zypp::Url &/*url*/
, Error /*error*/
, const std::string &/*description*/ )
{ return ABORT; }
virtual void finish(
const zypp::Url &/*url*/
, Error /*error*/
, const std::string &/*reason*/ )
{}
};
struct RepoReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE // skip refresh, ignore failed refresh
};
enum Error {
NO_ERROR,
NOT_FOUND, // the requested Url was not found
IO, // IO error
INVALID // th source is invalid
};
virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
virtual bool progress( const ProgressData &/*task*/ )
{ return true; }
virtual Action problem(
Repository /*source*/
, Error /*error*/
, const std::string &/*description*/ )
{ return ABORT; }
virtual void finish(
Repository /*source*/
, const std::string &/*task*/
, Error /*error*/
, const std::string &/*reason*/ )
{}
};
/////////////////////////////////////////////////////////////////
} // namespace source
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
namespace media
{
// media change request callback
struct MediaChangeReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE, // ignore this media in future, not available anymore
IGNORE_ID, // ignore wrong medium id
CHANGE_URL, // change media URL
EJECT // eject the medium
};
enum Error {
NO_ERROR,
NOT_FOUND, // the medie not found at all
IO, // error accessing the media
INVALID, // media is broken
WRONG, // wrong media, need a different one
IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
};
/**
*
* \param url in: url for which the media is requested,
* out: url to use instead of the original one
* \param mediumNr requested medium number
* \param label label of requested medium
* \param error type of error from \ref Error enum
* \param description error message (media not desired or error foo occured)
* \param devices list of the available devices (for eject)
* \param dev_current in: index of the currently used device in the \a devices list
* out: index of the devices to be ejected in the \a devices list
* \return \ref Action (ABORT by default)
*/
virtual Action requestMedia(
Url & /* url (I/O parameter) */
, unsigned /*mediumNr*/
, const std::string & /* label */
, Error /*error*/
, const std::string & /*description*/
, const std::vector<std::string> & /* devices */
, unsigned int & /* dev_current (I/O param) */
) { return ABORT; }
};
// progress for downloading a file
struct DownloadProgressReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE // ignore the failure
};
enum Error {
NO_ERROR,
NOT_FOUND, // the requested Url was not found
IO, // IO error
ACCESS_DENIED, // user authent. failed while accessing restricted file
ERROR // other error
};
virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
/**
* Download progress.
*
* \param value Percentage value.
* \param file File URI.
* \param dbps_avg Average download rate so far. -1 if unknown.
* \param dbps_current Current download (cca last 1 sec). -1 if unknown.
*/
virtual bool progress(int /*value*/, const Url &/*file*/,
double dbps_avg = -1,
double dbps_current = -1)
{ return true; }
virtual Action problem(
const Url &/*file*/
, Error /*error*/
, const std::string &/*description*/
) { return ABORT; }
virtual void finish(
const Url &/*file*/
, Error /*error*/
, const std::string &/*reason*/
) {}
};
// authentication issues report
struct AuthenticationReport : public callback::ReportBase
{
/**
* Prompt for authentication data.
*
* \param url URL which required the authentication
* \param msg prompt text
* \param auth_data input/output object for handling authentication
* data. As an input parameter auth_data can be prefilled with
* username (from previous try) or auth_type (available
* authentication methods aquired from server (only CurlAuthData)).
* As an output parameter it serves for sending username, pasword
* or other special data (derived AuthData objects).
* \return true if user chooses to continue with authentication,
* false otherwise
*/
virtual bool prompt(const Url & /* url */,
const std::string & /* msg */,
AuthData & /* auth_data */)
{
return false;
}
};
/////////////////////////////////////////////////////////////////
} // namespace media
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
namespace target
{
/** Request to display the pre commit message of a patch. */
struct PatchMessageReport : public callback::ReportBase
{
/** Display \c patch->message().
* Return \c true to continue, \c false to abort commit.
*/
virtual bool show( Patch::constPtr & /*patch*/ )
{ return true; }
};
/** Indicate execution of a patch script. This is a sort of
* \c %post script shipped by a package and to be executed
* after the package was installed.
*/
struct PatchScriptReport : public callback::ReportBase
{
enum Notify { OUTPUT, PING };
enum Action {
ABORT, // abort commit and return error
RETRY, // (re)try to execute this script
IGNORE // ignore any failue and continue
};
/** Start executing the script provided by package.
*/
virtual void start( const Package::constPtr & /*package*/,
const Pathname & /*script path*/ )
{}
/** Progress provides the script output. If the script is quiet,
* from time to time still-alive pings are sent to the ui. Returning \c FALSE
* aborts script execution.
*/
virtual bool progress( Notify /*OUTPUT or PING*/,
const std::string & /*output*/ = std::string() )
{ return true; }
/** Report error. */
virtual Action problem( const std::string & /*description*/ )
{ return ABORT; }
/** Report success. */
virtual void finish()
{}
};
///////////////////////////////////////////////////////////////////
namespace rpm
{
// progress for installing a resolvable
struct InstallResolvableReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE // ignore the failure
};
enum Error {
NO_ERROR,
NOT_FOUND, // the requested Url was not found
IO, // IO error
INVALID // th resolvable is invalid
};
// the level of RPM pushing
/** \deprecated We fortunately no longer do 3 attempts. */
enum RpmLevel {
RPM,
RPM_NODEPS,
RPM_NODEPS_FORCE
};
virtual void start(
Resolvable::constPtr /*resolvable*/
) {}
virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
{ return true; }
virtual Action problem(
Resolvable::constPtr /*resolvable*/
, Error /*error*/
, const std::string &/*description*/
, RpmLevel /*level*/
) { return ABORT; }
virtual void finish(
Resolvable::constPtr /*resolvable*/
, Error /*error*/
, const std::string &/*reason*/
, RpmLevel /*level*/
) {}
};
// progress for removing a resolvable
struct RemoveResolvableReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE // ignore the failure
};
enum Error {
NO_ERROR,
NOT_FOUND, // the requested Url was not found
IO, // IO error
INVALID // th resolvable is invalid
};
virtual void start(
Resolvable::constPtr /*resolvable*/
) {}
virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
{ return true; }
virtual Action problem(
Resolvable::constPtr /*resolvable*/
, Error /*error*/
, const std::string &/*description*/
) { return ABORT; }
virtual void finish(
Resolvable::constPtr /*resolvable*/
, Error /*error*/
, const std::string &/*reason*/
) {}
};
// progress for rebuilding the database
struct RebuildDBReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE // ignore the failure
};
enum Error {
NO_ERROR,
FAILED // failed to rebuild
};
virtual void start(Pathname /*path*/) {}
virtual bool progress(int /*value*/, Pathname /*path*/)
{ return true; }
virtual Action problem(
Pathname /*path*/
, Error /*error*/
, const std::string &/*description*/
) { return ABORT; }
virtual void finish(
Pathname /*path*/
, Error /*error*/
, const std::string &/*reason*/
) {}
};
// progress for converting the database
struct ConvertDBReport : public callback::ReportBase
{
enum Action {
ABORT, // abort and return error
RETRY, // retry
IGNORE // ignore the failure
};
enum Error {
NO_ERROR,
FAILED // conversion failed
};
virtual void start(
Pathname /*path*/
) {}
virtual bool progress(int /*value*/, Pathname /*path*/)
{ return true; }
virtual Action problem(
Pathname /*path*/
, Error /*error*/
, const std::string &/*description*/
) { return ABORT; }
virtual void finish(
Pathname /*path*/
, Error /*error*/
, const std::string &/*reason*/
) {}
};
/////////////////////////////////////////////////////////////////
} // namespace rpm
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace target
///////////////////////////////////////////////////////////////////
class PoolQuery;
/** \name Locks */
//@{
/**
* Callback for cleaning locks which doesn't lock anything in pool.
*/
struct CleanEmptyLocksReport : public callback::ReportBase
{
/**
* action performed by cleaning api to specific lock
*/
enum Action {
ABORT, /**< abort and return error */
DELETE, /**< delete empty lock */
IGNORE /**< skip empty lock */
};
/**
* result of cleaning
*/
enum Error {
NO_ERROR, /**< no problem */
ABORTED /** cleaning aborted by user */
};
/**
* cleaning is started
*/
virtual void start(
) {}
/**
* progress of cleaning specifies in percents
* \return if continue
*/
virtual bool progress(int /*value*/)
{ return true; }
/**
* When find empty lock ask what to do with it
* \return action
*/
virtual Action execute(
const PoolQuery& /*error*/
) { return DELETE; }
/**
* cleaning is done
*/
virtual void finish(
Error /*error*/
) {}
};
/**
* this callback handles merging old locks with newly added or removed
*/
struct SavingLocksReport : public callback::ReportBase
{
/**
* action for old lock which is in conflict
* \see ConflictState
*/
enum Action {
ABORT, /**< abort and return error*/
DELETE, /**< delete conflicted lock */
IGNORE /**< skip conflict lock */
};
/**
* result of merging
*/
enum Error {
NO_ERROR, /**< no problem */
ABORTED /**< cleaning aborted by user */
};
/**
* type of conflict of old and new lock
*/
enum ConflictState{
SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
INTERSECT /**< locks lock some file and unlocking lock unlock only part
* of iti, so removing old lock can unlock more items in pool */
};
virtual void start() {}
/**
* merging still live
* \return if continue
*/
virtual bool progress()
{ return true; }
/**
* When user unlock something which is locked by non-identical query
*/
virtual Action conflict(
const PoolQuery&, /**< problematic query*/
ConflictState
) { return DELETE; }
virtual void finish(
Error /*error*/
) {}
};
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
#endif // ZYPP_ZYPPCALLBACKS_H