Skip to content

fix: use relative path for subfolder starter code downloads#635

Open
mayurigade-hub wants to merge 2 commits into
komalharshita:mainfrom
mayurigade-hub:fix/starter-code-subfolder-download
Open

fix: use relative path for subfolder starter code downloads#635
mayurigade-hub wants to merge 2 commits into
komalharshita:mainfrom
mayurigade-hub:fix/starter-code-subfolder-download

Conversation

@mayurigade-hub
Copy link
Copy Markdown

Summary [required]

When users clicked the Download button for projects whose starter code was stored inside a subfolder (e.g. starter_code/survey_form/index.html), the server was using os.path.basename which stripped the subfolder name and only kept the filename. Flask then looked for starter_code/index.html which does not exist, resulting in a 404 error. This PR fixes the issue by using os.path.relpath to preserve the full relative path from the starter code directory.

Related Issue [required]

Closes #524

Type of Change [required]

  • Bug fix — resolves a broken behaviour

What Was Changed [required]

File Change made
routes/main_routes.py Replaced os.path.basename with os.path.relpath in download_code route to preserve subfolder structure when serving files

How to Test This PR [required]

  1. Clone this branch: git checkout fix/starter-code-subfolder-download
  2. Install dependencies: pip install -r requirements.txt
  3. Run the app: python app.py
  4. Open http://127.0.0.1:5000
  5. Navigate to Project 9 (Survey Form)
  6. Click the Download button
  7. File should download successfully — no 404 error
  8. Repeat for a project without a subfolder to confirm nothing is broken
  9. Run tests: python tests/test_basic.py

Expected test output:

27 passed, 0 failed out of 27 tests

Test Results [required]

paste output here

Self-Review Checklist [required]

  • I have read CONTRIBUTING.md and followed all guidelines
  • My branch name follows the convention: fix/starter-code-subfolder-download
  • I have run python tests/test_basic.py and all 27 tests pass
  • I have run flake8 . locally and there are no errors
  • I have not introduced any print() or console.log() debug statements
  • Every new function I wrote has a docstring
  • I have not modified files outside the scope of the linked issue

Notes for Reviewer

The only logic change is in the download_code route inside routes/main_routes.py. The duplicate import os inside the function was also removed since os is already imported at the top of the file.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

@mayurigade-hub is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc-2026 type:bug Something isn't working labels May 26, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Thank you for submitting your first pull request to DevPath.

Before review:

  • Complete the PR template fully
  • Ensure all tests pass
  • Link your PR to an issue
  • Keep changes scoped to the issue

A maintainer will review your contribution soon.

@mayurigade-hub
Copy link
Copy Markdown
Author

hello maintainers!

please review this PR.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc-2026 type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Starter code downloads fail with 404 for projects in subfolders

1 participant