mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -05:00
fix tmp handling
This commit is contained in:
@@ -34,18 +34,13 @@ class DownloadError(FFmpegError):
|
|||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def temp_path_context():
|
def temp_path_context():
|
||||||
"""Context manager for temporary path creation and cleanup"""
|
"""Context manager for temporary path creation and cleanup"""
|
||||||
# Create a unique temporary directory within videoarchiver/tmp
|
# Create a temporary directory using system temp directory
|
||||||
tmp_base = Path("videoarchiver/tmp")
|
temp_dir = tempfile.mkdtemp(prefix="ffmpeg_")
|
||||||
tmp_base.mkdir(parents=True, exist_ok=True)
|
|
||||||
temp_dir = tmp_base / f"ffmpeg_{int(time.time())}_{os.getpid()}"
|
|
||||||
temp_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.chmod(str(temp_dir), stat.S_IRWXU)
|
yield temp_dir
|
||||||
yield str(temp_dir)
|
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(str(temp_dir), ignore_errors=True)
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error cleaning up temp directory {temp_dir}: {e}")
|
logger.error(f"Error cleaning up temp directory {temp_dir}: {e}")
|
||||||
|
|
||||||
@@ -87,11 +82,13 @@ class FFmpegManager:
|
|||||||
RETRY_DELAY = 1 # seconds
|
RETRY_DELAY = 1 # seconds
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Set up tmp directory path
|
# Use system temp directory for temporary files
|
||||||
self.tmp_path = Path("videoarchiver/tmp")
|
self.tmp_path = Path(tempfile.gettempdir()) / "ffmpeg_tmp"
|
||||||
self.tmp_path.mkdir(parents=True, exist_ok=True)
|
try:
|
||||||
if platform.system() != "Windows":
|
self.tmp_path.mkdir(parents=True, exist_ok=True)
|
||||||
self.tmp_path.chmod(0o755)
|
except Exception as e:
|
||||||
|
logger.warning(f"Could not create tmp directory, using system temp: {e}")
|
||||||
|
self.tmp_path = Path(tempfile.gettempdir())
|
||||||
|
|
||||||
# Use XDG_DATA_HOME or fallback to ~/.local/share for Linux/macOS
|
# Use XDG_DATA_HOME or fallback to ~/.local/share for Linux/macOS
|
||||||
if platform.system() in ["Linux", "Darwin"]:
|
if platform.system() in ["Linux", "Darwin"]:
|
||||||
@@ -105,11 +102,14 @@ class FFmpegManager:
|
|||||||
try:
|
try:
|
||||||
self.base_path.mkdir(parents=True, exist_ok=True)
|
self.base_path.mkdir(parents=True, exist_ok=True)
|
||||||
if platform.system() != "Windows":
|
if platform.system() != "Windows":
|
||||||
# Set directory permissions to rwxr-xr-x (755)
|
# Try to set directory permissions, but don't fail if we can't
|
||||||
self.base_path.chmod(0o755)
|
try:
|
||||||
logger.info(f"Created bin directory with permissions: {oct(self.base_path.stat().st_mode)[-3:]}")
|
self.base_path.chmod(0o755)
|
||||||
|
logger.info(f"Created bin directory with permissions: {oct(self.base_path.stat().st_mode)[-3:]}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Could not set bin directory permissions: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to create/set permissions on bin directory: {e}")
|
logger.error(f"Failed to create bin directory: {e}")
|
||||||
raise FFmpegError(f"Failed to initialize FFmpeg directory: {e}")
|
raise FFmpegError(f"Failed to initialize FFmpeg directory: {e}")
|
||||||
|
|
||||||
# Get system architecture
|
# Get system architecture
|
||||||
|
|||||||
Reference in New Issue
Block a user