mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
fix imports
This commit is contained in:
36
videoarchiver/utils/path_manager.py
Normal file
36
videoarchiver/utils/path_manager.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Path management utilities"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
import stat
|
||||
import logging
|
||||
import contextlib
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
@contextlib.contextmanager
|
||||
def temp_path_context():
|
||||
"""Context manager for temporary path creation and cleanup"""
|
||||
temp_dir = tempfile.mkdtemp(prefix="videoarchiver_")
|
||||
try:
|
||||
# Ensure proper permissions
|
||||
os.chmod(temp_dir, stat.S_IRWXU)
|
||||
yield temp_dir
|
||||
finally:
|
||||
try:
|
||||
# Ensure all files are deletable
|
||||
for root, dirs, files in os.walk(temp_dir):
|
||||
for d in dirs:
|
||||
try:
|
||||
os.chmod(os.path.join(root, d), stat.S_IRWXU)
|
||||
except OSError:
|
||||
pass
|
||||
for f in files:
|
||||
try:
|
||||
os.chmod(os.path.join(root, f), stat.S_IRWXU)
|
||||
except OSError:
|
||||
pass
|
||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||
except Exception as e:
|
||||
logger.error(f"Error cleaning up temp directory {temp_dir}: {e}")
|
||||
Reference in New Issue
Block a user