From c4c53d66794b67e70be3e486336784f5b7cd3fa6 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Fri, 10 Jan 2025 13:35:32 +0100 Subject: [PATCH] refs #1326 add ogDeleteTree() --- client/lib/engine/bin/FileLib.py | 51 ++++++++++++++++---------- client/lib/engine/bin/FileSystemLib.py | 7 +--- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/client/lib/engine/bin/FileLib.py b/client/lib/engine/bin/FileLib.py index 433b6ed..bc8de5e 100755 --- a/client/lib/engine/bin/FileLib.py +++ b/client/lib/engine/bin/FileLib.py @@ -261,30 +261,41 @@ def ogDeleteFile (disk=None, par=None, container=None, file=None): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, str (e)) return -def ogDeleteTree(*args): - # Variables locales. - DIR = None - if "help" in args: - SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir", "$FUNCNAME 1 2 /tmp/newdir") + +#/** +# ogDeleteTree [ str_repo | int_ndisk int_npartition ] path_dirpath +#@brief Metafunción que borra todo un subárbol de directorios de un dispositivo. +#@see ogGetPath +#*/ ## +#ogDeleteTree (container='REPO', file='/tmp/newdir') +#ogDeleteTree (disk=1, par=2, file='/tmp/newdir') +def ogDeleteTree (disk=None, par=None, container=None, file=None): + if file is None: + raise TypeError ('missing required argument: "file"') + + if container is not None: + if disk is None and par is None: + ## we were given container= + src = container + else: + raise TypeError ('argument "container" can be specified along neither "disk" nor "par"') + else: + if disk is not None and par is not None: + ## we were given disk= par= + src = f'{disk} {par}' + else: + ## we were given nothing + raise TypeError ('either "container" or both "disk" and "par" must be specified') + + f = ogGetPath (src=src, file=file) + if not f: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{src} {file}') return - # Comprobar que existe el directorio y borrarlo con su contenido. - DIR = ogGetPath(*args) - if not DIR: - SystemLib.ogRaiseError( - "session", - ogGlobals.OG_ERR_NOTFOUND, - f"Not found: {args}" - ) - return try: - shutil.rmtree(DIR) + shutil.rmtree (f) except OSError as e: - SystemLib.ogRaiseError( - "session", - ogGlobals.OG_ERR_NOTFOUND, - f"{e}" - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, e) return diff --git a/client/lib/engine/bin/FileSystemLib.py b/client/lib/engine/bin/FileSystemLib.py index bcb7d79..f1953ec 100755 --- a/client/lib/engine/bin/FileSystemLib.py +++ b/client/lib/engine/bin/FileSystemLib.py @@ -654,12 +654,7 @@ def ogMountFs (disk, par): if mntdir: return mntdir if ogIsLocked (disk, par): - print (f'nati: ogMountFs: is locked disk ({disk}) par ({par})') - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_LOCKED, - f"{ogGlobals.lang.MSG_PARTITION}, {disk} {par}" - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_LOCKED, f'{ogGlobals.lang.MSG_PARTITION}, {disk} {par}') return # El camino de un dispositivo normal comienza por el carácter "/".