diff options
author | 2005-02-06 12:56:40 +0000 | |
---|---|---|
committer | 2005-02-06 12:56:40 +0000 | |
commit | 8275f259cc1092074002cf9a9fc66eed4696da94 (patch) | |
tree | 14b0edc509d63c937fabde479f7d3566cbae9d51 | |
parent | bin/ebuild.sh: Completed renaming of "maketest" to "test". RESTRICT (diff) | |
download | portage-cvs-8275f259cc1092074002cf9a9fc66eed4696da94.tar.gz portage-cvs-8275f259cc1092074002cf9a9fc66eed4696da94.tar.bz2 portage-cvs-8275f259cc1092074002cf9a9fc66eed4696da94.zip |
Included the BSD chflags support from spb and added a check to ensure it
exists and is valid before it's used in any code.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | pym/portage.py | 70 | ||||
-rw-r--r-- | src/bsd-flags/PKG-INFO | 10 | ||||
-rw-r--r-- | src/bsd-flags/chflags.c | 161 | ||||
-rw-r--r-- | src/bsd-flags/setup.cfg | 6 | ||||
-rw-r--r-- | src/bsd-flags/setup.py | 24 |
6 files changed, 273 insertions, 5 deletions
@@ -1,12 +1,17 @@ # ChangeLog for Portage; the Gentoo Linux ports system # Copyright 1999-2005 Gentoo Foundation; Distributed under the GPL v2 -# $Id: ChangeLog,v 1.796.2.67 2005/02/06 02:48:43 jstubbs Exp $ +# $Id: ChangeLog,v 1.796.2.68 2005/02/06 12:56:39 carpaski Exp $ MAJOR CHANGES in 2.0.51: 1. /var/cache/edb/virtuals is no longer used at all. It's calculated now. 2. /var/cache/edb/world is now /var/lib/portage/world. 3. /etc/portage/profile/virtuals is _USER_ configs only. + 06 Feb 2005; Nicholas Jones <carpaski@gentoo.org> portage.py, src/chflags: + Addition of BSD chflags support (from spb@gentoo.org). Wrapped all the + calls within a check for the modules existance so we can reduce any problems + due to a failing or missing module. Internally renamed it bsd_chflags. + 06 Feb 2005; Jason Stubbs <jstubbs@gentoo.org> bin/ebuild.sh: Completed renaming of "maketest" to "test". RESTRICT supports both. #77446 diff --git a/pym/portage.py b/pym/portage.py index c10424a..0a9413e 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -1,10 +1,10 @@ # portage.py -- core Portage functionality # Copyright 1998-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/portage.py,v 1.524.2.38 2005/02/05 14:31:25 jstubbs Exp $ -cvs_id_string="$Id: portage.py,v 1.524.2.38 2005/02/05 14:31:25 jstubbs Exp $"[5:-2] +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/portage.py,v 1.524.2.39 2005/02/06 12:56:39 carpaski Exp $ +cvs_id_string="$Id: portage.py,v 1.524.2.39 2005/02/06 12:56:39 carpaski Exp $"[5:-2] -VERSION="$Revision: 1.524.2.38 $"[11:-2] + "-cvs" +VERSION="$Revision: 1.524.2.39 $"[11:-2] + "-cvs" # =========================================================================== # START OF IMPORTS -- START OF IMPORTS -- START OF IMPORTS -- START OF IMPORT @@ -52,6 +52,16 @@ except: sys.exit(127) try: + # XXX: This should get renamed to bsd_chflags, I think. + import chflags + bsd_chflags = chflags +except SystemExit, e: + raise +except: + # XXX: This should get renamed to bsd_chflags, I think. + bsd_chflags = None + +try: import cvstree import xpak import getbinpkg @@ -2650,10 +2660,18 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): be preserved even when moving across filesystems. Returns true on success and false on failure. Move is atomic.""" #print "movefile("+str(src)+","+str(dest)+","+str(newmtime)+","+str(sstat)+")" - global lchown + global lchown + try: if not sstat: sstat=os.lstat(src) + if bsd_chflags: + sflags=bsd_chflags.lgetflags(src) + if sflags < 0: + # Problem getting flags... + writemsg("!!! Couldn't get flags for "+dest+"\n") + return None + except SystemExit, e: raise except Exception, e: @@ -2670,6 +2688,24 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): dstat=os.lstat(os.path.dirname(dest)) destexists=0 + if bsd_chflags: + # Check that we can actually unset schg etc flags... + # Clear the flags on source and destination; we'll reinstate them after merging + if(destexists): + if bsd_chflags.lchflags(dest, 0) < 0: + writemsg("!!! Couldn't clear flags on file being merged: \n ") + # We might have an immutable flag on the parent dir; save and clear. + pflags=bsd_chflags.lgetflags(os.path.dirname(dest)) + bsd_chflags.lchflags(os.path.dirname(dest), 0) + + # Don't bother checking the return value here; if it fails then the next line will catch it. + bsd_chflags.lchflags(src, 0) + + if bsd_chflags.lhasproblems(src)>0 or (destexists and bsd_chflags.lhasproblems(dest)>0) or bsd_chflags.lhasproblems(os.path.dirname(dest))>0: + # This is bad: we can't merge the file with these flags set. + writemsg("!!! Can't merge file "+dest+" because of flags set\n") + return None + if destexists: if stat.S_ISLNK(dstat[stat.ST_MODE]): try: @@ -2694,6 +2730,12 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): else: os.symlink(target,dest) lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) + if bsd_chflags: + # Restore the flags we saved before moving + if bsd_chflags.lchflags(dest, sflags) < 0 or bsd_chflags.lchflags(os.path.dirname(dest), pflags) < 0: + writemsg("!!! Couldn't restore flags ("+str(flags)+") on " + dest+":\n") + writemsg("!!! %s\n" % str(e)) + return None return os.lstat(dest)[stat.ST_MTIME] except SystemExit, e: raise @@ -2767,6 +2809,13 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): else: os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME])) newmtime=sstat[stat.ST_MTIME] + + if bsd_chflags: + # Restore the flags we saved before moving + if bsd_chflags.lchflags(dest, sflags) < 0 or bsd_chflags.lchflags(os.path.dirname(dest), pflags) < 0: + writemsg("!!! Couldn't restore flags ("+str(sflags)+") on " + dest+":\n") + return None + return newmtime def merge(mycat,mypkg,pkgloc,infloc,myroot,mysettings,myebuild=None): @@ -6593,6 +6642,13 @@ class dblink: # we are merging a directory if mydmode!=None: # destination exists + + if bsd_chflags: + # Save then clear flags on dest. + dflags=bsd_chflags.lgetflags(mydest) + if(bsd_chflags.lchflags(mydest, 0)<0): + writemsg("!!! Couldn't clear flags on '"+mydest+"'.\n") + if not os.access(mydest, os.W_OK): pkgstuff = pkgsplit(self.pkg) writemsg("\n!!! Cannot write to '"+mydest+"'.\n") @@ -6605,6 +6661,8 @@ class dblink: if stat.S_ISLNK(mydmode) or stat.S_ISDIR(mydmode): # a symlink to an existing directory will work for us; keep it: print "---",mydest+"/" + if bsd_chflags: + bsd_chflags.lchflags(mydest, dflags) else: # a non-directory and non-symlink-to-directory. Won't work for us. Move out of the way. if movefile(mydest,mydest+".backup", mysettings=self.settings) == None: @@ -6616,6 +6674,8 @@ class dblink: selinux.secure_mkdir(mydest,sid) else: os.mkdir(mydest) + if bsd_chflags: + bsd_chflags.lchflags(mydest, dflags) os.chmod(mydest,mystat[0]) lchown(mydest,mystat[4],mystat[5]) print ">>>",mydest+"/" @@ -6627,6 +6687,8 @@ class dblink: else: os.mkdir(mydest) os.chmod(mydest,mystat[0]) + if bsd_chflags: + bsd_chflags.lchflags(mydest, bsd_chflags.lgetflags(mysrc)) lchown(mydest,mystat[4],mystat[5]) print ">>>",mydest+"/" outfile.write("dir "+myrealdest+"\n") diff --git a/src/bsd-flags/PKG-INFO b/src/bsd-flags/PKG-INFO new file mode 100644 index 0000000..f2cb5c5 --- /dev/null +++ b/src/bsd-flags/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: bsd-chflags +Version: 0.1 +Summary: UNKNOWN +Home-page: UNKNOWN +Author: Stephen Bennett +Author-email: spb@gentoo.org +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/src/bsd-flags/chflags.c b/src/bsd-flags/chflags.c new file mode 100644 index 0000000..622f5b8 --- /dev/null +++ b/src/bsd-flags/chflags.c @@ -0,0 +1,161 @@ +/* $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/src/bsd-flags/chflags.c,v 1.1.2.1 2005/02/06 12:56:40 carpaski Exp $ */ + +#include "Python.h" + +#include <sys/stat.h> + +static char chflags_lchflags__doc__[]; +static PyObject * chflags_lchflags(PyObject *self, PyObject *args); +static char chflags_lgetflags__doc__[]; +static PyObject * chflags_lgetflags(PyObject *self, PyObject *args); +static char chflags_lhasproblems__doc__[]; +static PyObject * chflags_lhasproblems(PyObject *self, PyObject *args); + +static char chflags__doc__[] = "Provide some operations for manipulating" \ + "FreeBSD's filesystem flags"; + +static PyMethodDef chflags_methods[] = { + {"lchflags", chflags_lchflags, METH_VARARGS, chflags_lchflags__doc__}, + {"lgetflags", chflags_lgetflags, METH_VARARGS, chflags_lgetflags__doc__}, + {"lhasproblems", chflags_lhasproblems, METH_VARARGS, chflags_lhasproblems__doc__}, + {NULL, NULL} +}; + +static char chflags_lchflags__doc__[] = +"lchflags(path, flags) -> None\n\ +Change the flags on path to equal flags."; + +static char chflags_lgetflags__doc__[] = +"lgetflags(path) -> Integer\n\ +Returns the file flags on path."; + +static char chflags_lhasproblems__doc__[] = +"lhasproblems(path) -> Integer\n\ +Returns 1 if path has any flags set that prevent write operations;\n\ +0 otherwise."; + +static const unsigned long problemflags=0x00160016; + +#if defined __FreeBSD__ +static PyObject *chflags_lchflags(PyObject *self, PyObject *args) +{ + char *path = NULL; + int flags; + int res; + + if (!PyArg_ParseTuple(args, "eti:lchflags", + Py_FileSystemDefaultEncoding, &path, + &flags)) + { + return NULL; + } + + res = lchflags(path, flags); + + PyMem_Free(path); + return PyInt_FromLong((long)res); +} + +static PyObject *chflags_lhasproblems(PyObject *self, PyObject *args) +{ + char *path = NULL; + struct stat sb; + int res; + + if (!PyArg_ParseTuple(args, "et:lhasproblems", + Py_FileSystemDefaultEncoding, &path)) + { + return NULL; + } + + res = stat(path, &sb); + + PyMem_Free(path); + + if (res < 0) + { + return PyInt_FromLong((long)res); + } + + if (sb.st_flags & problemflags) + return PyInt_FromLong(1); + else + return PyInt_FromLong(0); +} + +static PyObject *chflags_lgetflags(PyObject *self, PyObject *args) +{ + char *path = NULL; + struct stat sb; + int res; + + if (!PyArg_ParseTuple(args, "et:lgetflags", + Py_FileSystemDefaultEncoding, &path)) + { + return NULL; + } + + res = lstat(path, &sb); + + if (res < 0) + { + PyMem_Free(path); + return PyInt_FromLong((long)res); + } + + PyMem_Free(path); + + return PyInt_FromLong((long)sb.st_flags); +} + +#else +#warning Not on FreeBSD; building dummy lchflags + +static PyObject *chflags_lgetflags(PyObject *self, PyObject *args) +{ + /* Obviously we can't set flags if the OS/filesystem doesn't support them. */ + return PyInt_FromLong(0); +} + +static PyObject *chflags_lchflags(PyObject *self, PyObject *args) +{ + /* If file system flags aren't supported, just return 0, + as the effect is basically the same. */ + return PyInt_FromLong(0); +} + +static PyObject *chflags_lhasproblems(PyObject *self, PyObject *args) +{ + return PyInt_FromLong(0); +} + +#endif + +static int ins(PyObject *m, char *symbolname, int value) +{ + return PyModule_AddIntConstant(m, symbolname, value); +} + +DL_EXPORT(void) initchflags(void) +{ + PyObject *m; + m = Py_InitModule4("chflags", chflags_methods, chflags__doc__, + (PyObject*)NULL, PYTHON_API_VERSION); + + ins(m, "UF_SETTABLE", 0x0000ffff); + ins(m, "UF_NODUMP", 0x00000001); + ins(m, "UF_IMMUTABLE", 0x00000002); + ins(m, "UF_APPEND", 0x00000004); + ins(m, "UF_OPAQUE", 0x00000008); + ins(m, "UF_NOUNLINK", 0x00000010); + + ins(m, "SF_SETTABLE", 0xffff0000); + ins(m, "SF_NODUMP", 0x00010000); + ins(m, "SF_IMMUTABLE", 0x00020000); + ins(m, "SF_APPEND", 0x00040000); + ins(m, "SF_OPAQUE", 0x00080000); + ins(m, "SF_NOUNLINK", 0x00100000); + ins(m, "SF_SNAPSHOT", 0x00200000); + + ins(m, "PROBLEM_FLAGS", 0x00160016); +} diff --git a/src/bsd-flags/setup.cfg b/src/bsd-flags/setup.cfg new file mode 100644 index 0000000..ebf9c74 --- /dev/null +++ b/src/bsd-flags/setup.cfg @@ -0,0 +1,6 @@ +# bsd-flags +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/src/bsd-flags/setup.cfg,v 1.1.2.1 2005/02/06 12:56:40 carpaski Exp $ + +[bdist_rpm] +release = 1 +python=python2 diff --git a/src/bsd-flags/setup.py b/src/bsd-flags/setup.py new file mode 100644 index 0000000..aee9750 --- /dev/null +++ b/src/bsd-flags/setup.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/src/bsd-flags/setup.py,v 1.1.2.1 2005/02/06 12:56:40 carpaski Exp $ + +from os import chdir, stat +from distutils.core import setup, Extension + +setup (# Distribution meta-data + name = "bsd-chflags", + version = "0.1", + description = "", + author = "Stephen Bennett", + author_email = "spb@gentoo.org", + license = "", + long_description = \ + '''''', + ext_modules = [ Extension( + "chflags", + ["chflags.c"], + libraries=[], + ) + ], + url = "", + ) + |