From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id E3830138262 for ; Fri, 20 May 2016 14:27:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D5DCF1418A; Fri, 20 May 2016 14:27:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E24451418A for ; Fri, 20 May 2016 14:27:50 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id E52DE340C80 for ; Fri, 20 May 2016 14:27:49 +0000 (UTC) From: Mike Frysinger To: gentoo-catalyst@lists.gentoo.org Subject: [gentoo-catalyst] [PATCH 3/4] replace ad-hoc implementations of clear_dir Date: Fri, 20 May 2016 10:27:45 -0400 Message-Id: <1463754466-15028-3-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1463754466-15028-1-git-send-email-vapier@gentoo.org> References: <1463754466-15028-1-git-send-email-vapier@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Archives-Salt: b7f48c71-e806-4161-a957-4273c39e6aa6 X-Archives-Hash: e0b4837e95dd5f6b19ae7dcfbd6b19ad A few places copy & paste the logic we have in the clear_dir func. Punt them with a simple call to clear_dir. --- catalyst/base/stagebase.py | 9 +-------- catalyst/targets/netboot2.py | 10 ++-------- catalyst/targets/snapshot.py | 20 ++------------------ 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index 78e5b94..f0f3ba9 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -3,7 +3,6 @@ import os import imp import shutil import sys -from stat import ST_UID, ST_GID, ST_MODE from snakeoil import fileutils @@ -1202,13 +1201,7 @@ class StageBase(TargetBase, ClearBase, GenBase): log.warning('not a directory or does not exist, skipping "empty" operation: %s', x) continue log.info('Emptying directory %s', x) - # stat the dir, delete the dir, recreate the dir and set - # the proper perms and ownership - mystat=os.stat(myemp) - shutil.rmtree(myemp) - ensure_dirs(myemp, mode=0o755) - os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) - os.chmod(myemp,mystat[ST_MODE]) + clear_dir(myemp) self.resume.enable("empty") def remove(self): diff --git a/catalyst/targets/netboot2.py b/catalyst/targets/netboot2.py index da856ba..87dada3 100644 --- a/catalyst/targets/netboot2.py +++ b/catalyst/targets/netboot2.py @@ -4,12 +4,10 @@ netboot target, version 2 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation. import os -import shutil -from stat import ST_UID, ST_GID, ST_MODE from catalyst import log from catalyst.support import (CatalystError, normpath, cmd) -from catalyst.fileops import ensure_dirs, clear_path +from catalyst.fileops import (ensure_dirs, clear_dir, clear_path) from catalyst.base.stagebase import StageBase @@ -152,11 +150,7 @@ class netboot2(StageBase): log.info('Emptying directory %s', x) # stat the dir, delete the dir, recreate the dir and set # the proper perms and ownership - mystat=os.stat(myemp) - shutil.rmtree(myemp) - ensure_dirs(myemp, mode=0o755) - os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) - os.chmod(myemp,mystat[ST_MODE]) + clear_dir(myemp) self.resume.enable("empty") def set_action_sequence(self): diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py index 7ba94b2..8a9acdd 100644 --- a/catalyst/targets/snapshot.py +++ b/catalyst/targets/snapshot.py @@ -2,17 +2,13 @@ Snapshot target """ -import os -import shutil -from stat import ST_UID, ST_GID, ST_MODE - from DeComp.compress import CompressMap from catalyst import log from catalyst.support import normpath, cmd from catalyst.base.targetbase import TargetBase from catalyst.base.genbase import GenBase -from catalyst.fileops import ensure_dirs +from catalyst.fileops import (clear_dir, ensure_dirs) class snapshot(TargetBase, GenBase): @@ -102,16 +98,4 @@ class snapshot(TargetBase, GenBase): log.info('Cleaning up ...') def purge(self): - myemp=self.settings["tmp_path"] - if os.path.isdir(myemp): - log.notice('Emptying directory %s', myemp) - # stat the dir, delete the dir, recreate the dir and set - # the proper perms and ownership - mystat=os.stat(myemp) - # There's no easy way to change flags recursively in python - if os.uname()[0] == "FreeBSD": - os.system("chflags -R noschg "+myemp) - shutil.rmtree(myemp) - ensure_dirs(myemp, mode=0o755) - os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) - os.chmod(myemp,mystat[ST_MODE]) + clear_dir(self.settings['tmp_path']) -- 2.8.2