refs #1414 add ogDeleteCache, fix a bug
parent
1c6b5ace16
commit
0b95027e5e
|
@ -60,34 +60,36 @@ def ogCreateCache(ndisk=1, npart=4, partsize=None):
|
||||||
#@return (nada, por determinar)
|
#@return (nada, por determinar)
|
||||||
#@exception OG_ERR_FORMAT formato incorrecto.
|
#@exception OG_ERR_FORMAT formato incorrecto.
|
||||||
#@note Requisitos: fdisk, sgdisk, partprobe
|
#@note Requisitos: fdisk, sgdisk, partprobe
|
||||||
#@version 0.91 - Definición de caché local.
|
|
||||||
#@author Ramon Gomez, ETSII Universidad de Sevilla
|
|
||||||
#@date 2010/03/11
|
|
||||||
#@version 1.0.4 - Soporte para discos GPT.
|
|
||||||
#@author Universidad de Huelva
|
|
||||||
#@date 2012/03/13
|
|
||||||
#@version 1.0.6b - llamada correcta a ogUpdatePartitionTable
|
|
||||||
#@author Antonio Doblas Universidad de Málaga
|
|
||||||
#@date 2016/11/16
|
|
||||||
#@version 1.1.0 - Sustituir "sfdisk" por "fdisk" para discos MSDOS.
|
|
||||||
#@author Ramon Gomez, ETSII Universidad de Sevilla
|
|
||||||
#@date 2016/05/25
|
|
||||||
#*/ ##
|
#*/ ##
|
||||||
def ogDeleteCache():
|
def ogDeleteCache():
|
||||||
"""
|
|
||||||
Borra la partición utilizada para caché.
|
|
||||||
|
|
||||||
:raises RuntimeError: Si ocurre un error durante la eliminación de la partición de caché.
|
|
||||||
"""
|
|
||||||
cachepart = ogFindCache()
|
cachepart = ogFindCache()
|
||||||
if cachepart is None:
|
if not cachepart:
|
||||||
raise RuntimeError("No se encontró la partición de caché.")
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, ogGlobals.lang.MSG_NOCACHE)
|
||||||
|
return None
|
||||||
|
|
||||||
disk = f"/dev/sd{chr(96 + int(cachepart))}"
|
ndisk, npart = cachepart.split()
|
||||||
try:
|
disk = DiskLib.ogDiskToDev (ndisk)
|
||||||
subprocess.run(["parted", disk, "rm", cachepart], check=True)
|
|
||||||
except subprocess.CalledProcessError as e:
|
# Desmontar todos los sistemas de archivos del disco.
|
||||||
raise RuntimeError(f"Error al borrar la partición de caché: {e}")
|
FileSystemLib.ogUnmountAll (ndisk)
|
||||||
|
|
||||||
|
ptt = DiskLib.ogGetPartitionTableType (ndisk)
|
||||||
|
if 'GPT' == ptt:
|
||||||
|
# Si la tabla de particiones no es valida, volver a generarla.
|
||||||
|
if subprocess.run (['sgdisk', '-p', disk]).returncode:
|
||||||
|
subprocess.run (['gdisk', disk], input='2\nw\nY\n', text=True)
|
||||||
|
subprocess.run (['sgdisk', disk, f'-d{npart}'])
|
||||||
|
elif 'MSDOS' == ptt:
|
||||||
|
# Si la tabla de particiones no es valida, volver a generarla.
|
||||||
|
if subprocess.run (['parted', '-s', disk, 'print']).returncode:
|
||||||
|
subprocess.run (['fdisk', disk], input='w', text=True)
|
||||||
|
# Eliminar la partición de caché.
|
||||||
|
subprocess.run (['fdisk', disk], input=f'd\n{npart}\nw', text=True)
|
||||||
|
# Borrar etiqueta de la caché.
|
||||||
|
if os.path.exists ('/dev/disk/by-label/CACHE'):
|
||||||
|
os.unlink ('/dev/disk/by-label/CACHE')
|
||||||
|
#Actualiza la tabla de particiones en el kernel.
|
||||||
|
DiskLib.ogUpdatePartitionTable()
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
# ogFindCache
|
# ogFindCache
|
||||||
|
|
|
@ -851,7 +851,9 @@ def ogUnmountFs(disk, par):
|
||||||
#*/ ##
|
#*/ ##
|
||||||
def ogUnmountAll (disk):
|
def ogUnmountAll (disk):
|
||||||
DISK = DiskLib.ogDiskToDev (disk)
|
DISK = DiskLib.ogDiskToDev (disk)
|
||||||
for PART in range (1, DiskLib.ogGetPartitionsNumber (disk) + 1):
|
n = DiskLib.ogGetPartitionsNumber (disk)
|
||||||
|
if not n: return None
|
||||||
|
for PART in range (1, n+1):
|
||||||
if 'CACHE' != ogGetFsType (disk, PART):
|
if 'CACHE' != ogGetFsType (disk, PART):
|
||||||
ogUnmount (disk, PART)
|
ogUnmount (disk, PART)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from CacheLib import ogDeleteCache
|
||||||
|
|
||||||
|
ret = ogDeleteCache()
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
Loading…
Reference in New Issue