Skip to content

Add rename_recording endpoint - #117

Merged
ktshah04 merged 5 commits into
mainfrom
feature/video-filename-renaming
Mar 25, 2026
Merged

ktshah04 merged 5 commits into
mainfrom
feature/video-filename-renaming

Conversation

@loopback

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a rename_recording_entry() function to the recording database layer that updates the filename in SQLite and renames the directory on disk.
  • Exposes it via a new POST /rename_recording FastAPI endpoint accepting participant, current filename, and new filename.

Provides the backend support for IntelligentSensingAndRehabilitation/capture-app#8.

raise ValueError(f"Recording not found: participant={participant_name}, filename={old_filename}")

# Rename directory on disk if it exists
if os.path.exists(old_filename):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider revising this to raise an error if the directory does not exist to notify the user and so there is no potential for a DB/filesystem mismatch

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds backend support to rename an existing recording by updating its stored filename and exposing a new FastAPI endpoint for the capture app workflow.

Changes:

  • Added rename_recording_entry() to the SQLite/SQLAlchemy recording DB layer.
  • Added POST /rename_recording endpoint with a RenameRecordingData request model.
  • Wired the new DB function into the FastAPI backend.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
multi_camera/backend/recording_db.py Adds DB-layer rename helper that also attempts to rename on-disk content.
multi_camera/backend/fastapi.py Adds request model + POST /rename_recording route to call the DB-layer helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread multi_camera/backend/recording_db.py
Comment thread multi_camera/backend/fastapi.py
Comment on lines +302 to +306
# Rename directory on disk if it exists
if os.path.exists(old_filename):
os.rename(old_filename, new_filename)

recording.filename = new_filename

Copilot AI Mar 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old_filename stored in the DB appears to be a base path prefix (e.g., /.../trial_YYYYMMDD_HHMMSS) while the actual artifacts on disk are *.{serial}.mp4 plus a .json sidecar. os.path.exists(old_filename) will typically be false (no file/dir at that exact path), so the code will skip the filesystem rename but still update the DB, leaving the database and disk out of sync. Consider renaming all expected on-disk artifacts derived from recording.filename (e.g., .json and camera .mp4 files via a glob), and fail the request if none of them exist so you don’t silently desynchronize state.

Copilot uses AI. Check for mistakes.
Comment thread multi_camera/backend/recording_db.py
Adds a POST /api/v1/rename_recording endpoint that renames a recording's
directory on disk and updates the filename in the SQLite database. Used
by the capture app's debug mode to revise recording filenames after
capture.
…recording

Validates that new_name is a safe basename (no absolute paths, path separators, or '..' segments) and derives the full path from the existing recording's directory. Checks for DB and on-disk collisions before renaming. Returns HTTP 409 for conflicts.
@loopback
loopback force-pushed the feature/video-filename-renaming branch from 0c29e66 to 29bc17d Compare March 23, 2026 18:59
The capture app sends new_filename as a full relative path, not a bare basename. Revise validation to accept this: reject absolute paths and '..' segments, and verify the parent directory is unchanged (only the basename may differ).
@loopback

Copy link
Copy Markdown
Collaborator Author

Reviewed all four Copilot comments and pushed fixes in two commits (0c29e66, 3853038).

1. Path traversal / input validation (comments 3 and 5) — Fixed.
rename_recording_entry() now rejects absolute paths and .. segments, and verifies that the parent directory is unchanged (only the basename may differ). The capture app sends new_filename as a full relative path with the directory prefix preserved, so the validation accepts that form while still preventing traversal. Returns HTTP 400 (via ValueError) for invalid input.

2. Collision detection (comment 2) — Fixed.
Before renaming, the function now checks both the DB (existing Recording with matching filename) and disk (os.path.exists). Raises FileExistsError, which the endpoint maps to HTTP 409 Conflict.

3. Missing directory raises no error (comment 1) — No change.
If the directory doesn't exist on disk, the DB update proceeds silently. This is intentional — recordings may not yet have on-disk artifacts in all workflows. The path traversal fix above ensures this can't lead to writing outside the recording root.

4. Filename vs directory path mismatch (comment 4) — Not applicable.
recording.filename stores the recording directory path, not a file prefix. os.path.exists() and os.rename() operate on the directory correctly. The premise of this comment (that artifacts are individual *.mp4 files at the path) doesn't match the data model.

@copilot @ktshah04 — requesting re-review.

Copilot AI commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

@loopback I've opened a new pull request, #122, to work on those changes. Once the pull request is ready, I'll request review from you.

…lot/sub-pr-117

Add rename_recording endpoint with path validation and collision detection
@ktshah04
ktshah04 merged commit 6259c12 into main Mar 25, 2026
@loopback
loopback deleted the feature/video-filename-renaming branch March 25, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants