From 79c1ab34c08ce068823753dc9ad4638ea0b328ec Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Mon, 11 Nov 2024 17:15:38 +0100 Subject: [PATCH] refs #1101 add ogUnmount() and its dependency --- client/lib/engine/bin/FileSystemLib.py | 63 ++++++++++++++++---------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/client/lib/engine/bin/FileSystemLib.py b/client/lib/engine/bin/FileSystemLib.py index e99fd31..d8f5d1a 100755 --- a/client/lib/engine/bin/FileSystemLib.py +++ b/client/lib/engine/bin/FileSystemLib.py @@ -750,45 +750,62 @@ def ogUnlockPartition(int_ndisk, int_npartition): LOCKFILE = f"/var/lock/lock{PART.replace('/', '-')}" os.remove(LOCKFILE) -def ogUnmount(): - ogUnmountFs(*sys.argv[2:]) -def ogUnmountFs(int_ndisk, int_npartition): - FUNCNAME = ogUnmountFs.__name__ - # Si se solicita, mostrar ayuda. - if len(sys.argv) == 3 and sys.argv[2] == "help": - ogHelp("ogUnmountFs", "ogUnmountFs int_ndisk int_npartition", "ogUnmountFs 1 1") - return +#/** +# ogUnmount int_ndisk int_npartition +#@see ogUnmountFs +#*/ ## +def ogUnmount (disk, par): + ogUnmountFs (disk, par) - # Error si no se reciben 2 parámetros. - if len(sys.argv) != 3: - ogRaiseError(OG_ERR_FORMAT) - return +#/** +# ogUnmountFs int_ndisk int_nfilesys +#@brief Desmonta un sistema de archivos. +#@param int_ndisk nº de orden del disco +#@param int_nfilesys nº de orden del sistema de archivos +#@return Nada +#@exception OG_ERR_FORMAT Formato incorrecto. +#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. +#@warning La partición no está previamente montada o no se puede desmontar. +#*/ ## - # Obtener partición y punto de montaje. - PART = ogDiskToDev(int_ndisk, int_npartition) - MNTDIR = ogGetMountPoint(int_ndisk, int_npartition) +def ogUnmountFs(disk, par): + PART = DiskLib.ogDiskToDev (disk, par) + if not PART: return + MNTDIR = ogGetMountPoint (disk, par) # Si está montada, desmontarla. if MNTDIR: # Error si la particion está bloqueada. - if ogIsPartitionLocked(int_ndisk, int_npartition): - ogRaiseError(OG_ERR_LOCKED, f"{MSG_PARTITION}, {int_ndisk} {int_npartition}") + if ogIsLocked (disk, par): + ogRaiseError ([], ogGlobals.OG_ERR_LOCKED, f"{ogGlobals.lang.MSG_PARTITION}, {disk} {par}") return # Desmontar y borrar punto de montaje. try: - subprocess.run(["umount", PART], check=True, stderr=subprocess.DEVNULL) + subprocess.run(["umount", PART], check=True) except subprocess.CalledProcessError: - ogEcho("warning", f"{FUNCNAME}: {MSG_DONTUNMOUNT}: \"{int_ndisk}, {int_npartition}\"") + SystemLib.ogEcho("warning", f'ogUnmountFs: {ogGlobals.lang.MSG_DONTUNMOUNT}: "{disk}, {par}"') try: os.rmdir(MNTDIR) - except OSError: - os.remove(MNTDIR) + except: + try: + os.remove(MNTDIR) + except: + pass else: - ogEcho("warning", f"{MSG_DONTMOUNT}: \"{int_ndisk},{int_npartition}\"") - ogUnmountFs(int_ndisk, int_npartition) + SystemLib.ogEcho ([], "warning", f'{ogGlobals.lang.MSG_DONTMOUNT}: "{disk},{par}"') + +#/** +# ogUnmountAll int_ndisk +#@brief Desmonta todos los sistema de archivos de un disco, excepto el caché local. +#@param int_ndisk nº de orden del disco +#@return Nada +#@exception OG_ERR_FORMAT Formato incorrecto. +#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. +#@warning No se desmonta la partición marcada como caché local. +#*/ ## def ogUnmountAll(int_ndisk): # Si se solicita, mostrar ayuda. if len(sys.argv) == 3 and sys.argv[2] == "help":