Realiza varios ajustes para melhorar o tracking e o render de video
This commit is contained in:
@@ -23,16 +23,58 @@ def ensure_workspace(root: Path, folder_name: str) -> Path:
|
||||
|
||||
|
||||
def remove_paths(paths: Iterable[Path]) -> None:
|
||||
import logging
|
||||
import time
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
for path in paths:
|
||||
if not path.exists():
|
||||
continue
|
||||
if path.is_file() or path.is_symlink():
|
||||
path.unlink(missing_ok=True)
|
||||
else:
|
||||
for child in sorted(path.rglob("*"), reverse=True):
|
||||
if child.is_file() or child.is_symlink():
|
||||
child.unlink(missing_ok=True)
|
||||
elif child.is_dir():
|
||||
child.rmdir()
|
||||
path.rmdir()
|
||||
|
||||
# Try to remove with retries and better error handling
|
||||
max_retries = 3
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
if path.is_file() or path.is_symlink():
|
||||
path.unlink(missing_ok=True)
|
||||
else:
|
||||
for child in sorted(path.rglob("*"), reverse=True):
|
||||
if child.is_file() or child.is_symlink():
|
||||
try:
|
||||
child.unlink(missing_ok=True)
|
||||
except PermissionError:
|
||||
logger.warning(f"Não foi possível deletar {child}: sem permissão")
|
||||
# Try to change permissions and retry
|
||||
try:
|
||||
child.chmod(0o777)
|
||||
child.unlink(missing_ok=True)
|
||||
except Exception as e:
|
||||
logger.warning(f"Falha ao forçar deleção de {child}: {e}")
|
||||
elif child.is_dir():
|
||||
try:
|
||||
child.rmdir()
|
||||
except (PermissionError, OSError) as e:
|
||||
logger.warning(f"Não foi possível remover diretório {child}: {e}")
|
||||
|
||||
try:
|
||||
path.rmdir()
|
||||
except (PermissionError, OSError) as e:
|
||||
logger.warning(f"Não foi possível remover diretório {path}: {e}")
|
||||
break # Success, exit retry loop
|
||||
|
||||
except PermissionError as e:
|
||||
if attempt < max_retries - 1:
|
||||
logger.warning(f"Tentativa {attempt + 1}/{max_retries} falhou ao deletar {path}: {e}. Tentando novamente...")
|
||||
time.sleep(0.5) # Wait a bit before retry
|
||||
# Try to change permissions
|
||||
try:
|
||||
path.chmod(0o777)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
logger.error(f"Não foi possível deletar {path} após {max_retries} tentativas: {e}")
|
||||
except Exception as e:
|
||||
logger.error(f"Erro inesperado ao deletar {path}: {e}")
|
||||
break # Don't retry on unexpected errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user