Commit 0375fcf7 authored by Aryan Noshirvani's avatar Aryan Noshirvani

Fix real bug: os.rename fails cross-filesystem (found via new test)

The actual root cause of the CI-only 500, once the diagnostic from the
last commit surfaced it: [Errno 18] Invalid cross-device link. This
was never an environment/ffmpeg issue - it's a genuine pre-existing
bug in tag_and_convert_audio. os.rename() (the rename(2) syscall)
cannot move a file across filesystems/mounts; it only happened to work
on this dev VPS because /root/antigrav-stax-audio/temp and the app's
working directory share one partition. In CI, the build's working
directory is a separate volume from /root, so the exact same code
path fails every time. /music/upload's success path had zero test
coverage before this session, so nothing had ever actually exercised
this rename in an environment where it could fail.

Fixed with shutil.move(), which transparently falls back to copy+delete
when the destination isn't on the same filesystem - correct regardless
of deployment topology, not just this one VPS's current partition
layout.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCxXmJVvDFJVHTUi4QgNzi
parent 5df61425
Pipeline #993 passed with stage
in 5 minutes and 14 seconds
import os
import shutil
import aiohttp
from pydub import AudioSegment
from mutagen.mp3 import MP3
......@@ -18,7 +19,6 @@ async def tag_and_convert_audio(raw_file_path: str, candidate: dict) -> str:
# 1. Convert to MP3 (or skip if already MP3)
if raw_file_path.lower().endswith('.mp3'):
mp3_file_path = f"{raw_file_path}_tagged.mp3"
import shutil
shutil.copyfile(raw_file_path, mp3_file_path)
else:
mp3_file_path = f"{raw_file_path}.mp3"
......@@ -52,9 +52,13 @@ async def tag_and_convert_audio(raw_file_path: str, candidate: dict) -> str:
mp3.save(v2_version=3)
# 3. Rename file
# 3. Move into place. shutil.move (not os.rename) - the source lives under a temp dir
# that can be a different filesystem/mount from the destination (e.g. a separate CI
# build volume), and os.rename raises "Invalid cross-device link" (EXDEV) whenever
# source and destination aren't on the same filesystem. shutil.move falls back to a
# copy+delete in that case, so it works regardless of the deployment's mount topology.
safe_title = "".join([c for c in title if c.isalnum() or c==' ']).rstrip()
final_filename = f"{safe_title}.mp3" if safe_title else "Unknown Track.mp3"
os.rename(mp3_file_path, final_filename)
shutil.move(mp3_file_path, final_filename)
return final_filename
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment