From: Stefan Berger Subject: [PATCH] [Xend] Follow linked files Date: Wed, 31 Oct 2007 14:10:54 -0400 Message-ID: <1193854254.4221.3.camel@941e-2.watson.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-Ga1QvTJmC+TSUxKHn/Xv" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel List-Id: xen-devel@lists.xenproject.org --=-Ga1QvTJmC+TSUxKHn/Xv Content-Type: text/plain Content-Transfer-Encoding: 7bit I rewrote this so that multiple links are properly followed. Signed-off-by: Stefan Berger --=-Ga1QvTJmC+TSUxKHn/Xv Content-Disposition: attachment; filename=xend_acm_resource_follow_link.diff Content-Type: text/x-vhdl; name=xend_acm_resource_follow_link.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit --- xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py | 29 ++++++------------- 1 file changed, 10 insertions(+), 19 deletions(-) Index: root/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py +++ root/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py @@ -711,33 +711,24 @@ def unify_resname(resource, mustexist=Tr except: err("Resource spec '%s' contains no tap subtype" % resource) - import os - if typ in ["phy", "tap"]: + if typ in ["phy"]: if not resfile.startswith("/"): resfile = "/dev/" + resfile if mustexist: - stats = os.lstat(resfile) - if stat.S_ISLNK(stats[stat.ST_MODE]): - resolved = os.readlink(resfile) - if resolved[0] != "/": - resfile = os.path.join(os.path.dirname(resfile), resolved) - resfile = os.path.abspath(resfile) - else: - resfile = resolved + resfile = os.path.realpath(resfile) + try: stats = os.lstat(resfile) - if not (stat.S_ISBLK(stats[stat.ST_MODE])): + if not (stat.S_ISBLK(stats[stat.ST_MODE])): + err("Invalid resource") + except: err("Invalid resource") if typ in [ "file", "tap" ]: - if mustexist: - stats = os.lstat(resfile) - if stat.S_ISLNK(stats[stat.ST_MODE]): - resfile = os.readlink(resfile) - stats = os.lstat(resfile) - if not stat.S_ISREG(stats[stat.ST_MODE]): - err("Invalid resource") + resfile = os.path.realpath(resfile) + if mustexist and not os.path.isfile(resfile): + err("Invalid resource") - #file: resources must specified with absolute path + #file: resources must be specified with absolute path #vlan resources don't start with '/' if typ != "vlan": if (not resfile.startswith("/")) or \ --=-Ga1QvTJmC+TSUxKHn/Xv Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-Ga1QvTJmC+TSUxKHn/Xv--