[Aptitude-svn-commit] r4276 - in branches/aptitude-0.3/aptitude: .
src/generic/apt
Daniel Burrows
dburrows at costa.debian.org
Mon Sep 26 05:14:00 UTC 2005
Author: dburrows
Date: Mon Sep 26 05:13:57 2005
New Revision: 4276
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.cc
branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.h
Log:
Add initial support for detecting writes to a read-only cache.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Mon Sep 26 05:13:57 2005
@@ -1,5 +1,12 @@
2005-09-25 Daniel Burrows <dburrows at debian.org>
+ * src/generic/aptcache.cc, src/generic/aptcache.h:
+
+ Add support for making the cache 'read-only'; writing to a
+ read-only cache will generate what you could loosely describe as
+ a 'page fault', to be dealt with by slots connected to a public
+ signal.
+
* src/generic/util/bool_accumulate, src/ui/ui.h, src/vscreen/bool_accumulate, src/vscreen/vs_menu.h:
Move bool_accumulate to generic code.
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.cc (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.cc Mon Sep 26 05:13:57 2005
@@ -166,8 +166,9 @@
};
aptitudeDepCache::aptitudeDepCache(pkgCache *Cache, Policy *Plcy)
- :pkgDepCache(Cache, Plcy), dirty(false), package_states(NULL), lock(-1),
- group_level(0), mark_and_sweep_in_progress(false)
+ :pkgDepCache(Cache, Plcy), dirty(false), read_only(true),
+ package_states(NULL), lock(-1), group_level(0),
+ mark_and_sweep_in_progress(false)
{
// When the "install recommended packages" flag changes, collect garbage.
aptcfg->connect(PACKAGE "::Recommends-Important",
@@ -195,6 +196,11 @@
close(lock);
}
+void aptitudeDepCache::set_read_only(bool new_read_only)
+{
+ read_only = new_read_only;
+}
+
bool aptitudeDepCache::build_selection_list(OpProgress &Prog, bool WithLock,
bool do_initselections,
const char *status_fname)
@@ -227,6 +233,7 @@
if(lock!=-1)
close(lock);
lock=-1;
+ read_only = true;
return false;
}
}
@@ -242,6 +249,9 @@
else
state_file.Open(status_fname, FileFd::ReadOnly);
+ // Have to make the file NOT read-only to set up the initial state.
+ read_only = false;
+
if(!state_file.IsOpen())
{
_error->Discard();
@@ -407,6 +417,8 @@
Prog.Done();
+ read_only = (lock == -1);
+
return true;
}
@@ -414,6 +426,13 @@
bool ignore_removed,
undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
begin_action_group();
for(int iter=0; iter==0 || (iter==1 && with_autoinst); ++iter)
@@ -601,6 +620,13 @@
void aptitudeDepCache::set_new_flag(const pkgCache::PkgIterator &pkg,
bool is_new)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
aptitude_state &estate=get_ext_state(pkg);
if(estate.new_package && !is_new)
@@ -617,6 +643,13 @@
void aptitudeDepCache::forget_new(undoable **undoer)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
forget_undoer *undo=undoer?new forget_undoer(this):NULL;
for(pkgCache::PkgIterator i=PkgBegin(); !i.end(); i++)
@@ -769,6 +802,13 @@
undo_group *undo,
bool do_mark_and_sweep)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
pre_package_state_changed();
dirty=true;
@@ -805,6 +845,13 @@
void aptitudeDepCache::internal_mark_keep(const PkgIterator &Pkg, bool Soft, bool SetHold, undo_group *undo, bool do_mark_and_sweep)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
pre_package_state_changed();
dirty=true;
@@ -847,6 +894,13 @@
void aptitudeDepCache::set_candidate_version(const VerIterator &ver,
undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
dirty=true;
if(!ver.end())
@@ -888,6 +942,13 @@
void aptitudeDepCache::forbid_upgrade(const PkgIterator &pkg,
string verstr, undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
aptitude_state &estate=get_ext_state(pkg);
if(verstr!=estate.forbidver)
@@ -917,6 +978,13 @@
void aptitudeDepCache::mark_single_install(const PkgIterator &Pkg, undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
pre_package_state_changed();
dirty=true;
@@ -941,6 +1009,13 @@
bool set_auto,
undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
pre_package_state_changed();
dirty=true;
@@ -960,6 +1035,13 @@
bool aptitudeDepCache::all_upgrade(bool with_autoinst, undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return false;
+ }
+
pre_package_state_changed();
pkgProblemResolver fixer(this);
@@ -995,6 +1077,13 @@
bool aptitudeDepCache::try_fix_broken(pkgProblemResolver &fixer, undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return false;
+ }
+
pre_package_state_changed();
dirty=true;
bool founderr=false;
@@ -1020,6 +1109,13 @@
bool aptitudeDepCache::try_fix_broken(undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return false;
+ }
+
pkgProblemResolver fixer(this);
for(pkgCache::PkgIterator i=PkgBegin(); !i.end(); i++)
{
@@ -1047,6 +1143,13 @@
*/
void aptitudeDepCache::MarkFromDselect(const PkgIterator &Pkg)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
aptitude_state &state=get_ext_state(Pkg);
if(Pkg->SelectedState!=state.selection_state)
@@ -1119,6 +1222,13 @@
if(group_level==1)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
mark_and_sweep(undo);
cleanup_after_change(undo);
@@ -1141,6 +1251,13 @@
void aptitudeDepCache::restore_apt_state(const apt_state_snapshot *snapshot)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
memcpy(PkgState, snapshot->PkgState, sizeof(StateCache)*Head().PackageCount);
memcpy(DepState, snapshot->DepState, sizeof(char)*Head().DependsCount);
// memcpy doesn't work here because the aptitude_state structure
@@ -1303,6 +1420,13 @@
void aptitudeDepCache::apply_solution(const generic_solution<aptitude_universe> &sol,
undo_group *undo)
{
+ if(read_only && !read_only_permission())
+ {
+ if(group_level == 0)
+ read_only_fail();
+ return;
+ }
+
begin_action_group();
for(imm::map<aptitude_resolver_package, generic_solution<aptitude_universe>::action>::const_iterator
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.h (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/aptcache.h Mon Sep 26 05:13:57 2005
@@ -30,6 +30,8 @@
#include <config.h>
+#include <generic/util/bool_accumulate.h>
+
#include <apt-pkg/depcache.h>
#include <sigc++/signal.h>
@@ -151,6 +153,10 @@
*/
bool dirty;
+ /** This flag is \b true if the cache is in 'read-only' mode.
+ */
+ bool read_only;
+
// Some internal classes for undo information
class apt_undoer;
class forget_undoer;
@@ -253,6 +259,10 @@
void internal_mark_delete(const PkgIterator &Pkg, bool Purge, bool unused_delete, undo_group *undo, bool do_mark_sweep);
void internal_mark_keep(const PkgIterator &Pkg, bool Soft, bool SetHold, undo_group *undo, bool do_mark_sweep);
public:
+ /** Create a new depcache from the given cache and policy. By
+ * default, the depcache is readonly if and only if it is not
+ * locked.
+ */
aptitudeDepCache(pkgCache *cache, Policy *Plcy=0);
bool Init(OpProgress *Prog, bool WithLock,
@@ -343,6 +353,16 @@
// Marks the given package as having been autoinstalled (so it will be
// removed automatically) or having been installed manually.
+ /** Retrieve the read-only flag. */
+ bool get_read_only() const { return read_only; }
+
+ /** Set the read-only flag. If the cache is read-only, then any
+ * attempt to modify a package's state will instead call the
+ * read_only_alert() signal, which can either allow the
+ * modification to continue or cancel it.
+ */
+ void set_read_only(bool new_read_only);
+
/** Apply the given solution as a resolver result; any actions
* that it requests will be marked as having been performed to
* fulfill dependencies.
@@ -388,6 +408,17 @@
// (in particular, when package "new" states are forgotten)
sigc::signal0<void> package_category_changed;
+ /** This signal is emitted when the user attempts to modify the
+ * cache while it is in read-only mode. If any callback returns \b
+ * false, the modification is cancelled.
+ */
+ sigc::signal0<bool, accumulate_and> read_only_permission;
+
+ /** This signal is emitted when a read-only operation fails. It is
+ * emitted exactly once for every action group.
+ */
+ sigc::signal0<void> read_only_fail;
+
virtual ~aptitudeDepCache();
};
More information about the Aptitude-svn-commit
mailing list