diff --git a/client/lib/engine/bin/CacheLib.py b/client/lib/engine/bin/CacheLib.py index b67d530..fdb5698 100644 --- a/client/lib/engine/bin/CacheLib.py +++ b/client/lib/engine/bin/CacheLib.py @@ -57,22 +57,46 @@ def ogDeleteCache(): except subprocess.CalledProcessError as e: raise RuntimeError(f"Error al borrar la partición de caché: {e}") +#/** +# ogFindCache +#@brief Detecta la partición caché local. +#@param No requiere parametros +#@return int_ndisk int_npart - devuelve el par nº de disco-nº de partición . +#@warning Si no hay cache no devuelve nada +#*/ ## def ogFindCache(): - """ - Encuentra la partición que se usa como caché. + # Obtener el dispositivo del sistema de archivos etiquetado como "CACHE". + PART = subprocess.run (['blkid', '-L', 'CACHE'], capture_output=True, text=True).stdout.strip() - :return: El nombre de la partición de caché si se encuentra, de lo contrario None. - """ - try: - for disk in [f"/dev/sd{chr(97 + i)}" for i in range(26)]: # /dev/sda to /dev/sdz - result = subprocess.run(["sfdisk", "-d", disk], capture_output=True, text=True, check=True) - if "CA00" in result.stdout: - cachepart = [line.split()[0] for line in result.stdout.splitlines() if "CA00" in line][0] - return cachepart - except subprocess.CalledProcessError: - return None + # En discos nvme con particiones GPT la partición se detecta usando el tag PARTLABEL + if not PART: + out = subprocess.run (['blkid', '-t', 'PARTLABEL=CACHE'], capture_output=True, text=True).stdout.strip() + PART = out.split (':')[0] - return None + # Si no se detecta, obtener particiones marcadas de tipo caché en discos MSDOS. + if not PART: + out = subprocess.run (['sfdisk', '-l'], capture_output=True, text=True).stdout.splitlines() + for l in out: + elems = l.split (maxsplit=5) + if 6 > len (elems): continue + if 'ca' in elems[5] or 'a7' in elems[5]: + PART=elems[0] + break + + # Por último revisar todos los discos GPT y obtener las particiones etiquetadas como caché. + if not PART: + PART = '' + for d in ogDiskToDev(): + out = subprocess.run (['sgdisk', '-p', d], capture_output=True, text=True).stdout.splitlines() + for l in out: + elems = l.split (maxsplit=6) + if 7 > len (elems): continue + if 'CACHE' in elems[6]: + p = 'p' if 'nvme' in d else '' + PART += f' {d}{p}{elems[0]}' + + if not PART: return + return ogDevToDisk (PART.split()[0]) # usar la 1ª partición encontrada. def ogFormatCache(): """ @@ -209,4 +233,4 @@ def ogUnmountCache(): raise RuntimeError(f"Error al desmontar la partición de caché: {e}") # Eliminar el enlace simbólico de /mnt/ParticiónCache. - os.remove(f"/mnt/{cachepart}") \ No newline at end of file + os.remove(f"/mnt/{cachepart}")