Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25346 closed Cleanup/optimization (fixed)

collectstatic --clear doesn't delete broken symlinks from the STATIC_ROOT

Reported by: Evan Heidtmann Owned by: nobody
Component: contrib.staticfiles Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Evan Heidtmann)

In my STATIC_ROOT, I have a directory containing some broken symlinks.

I run ./manage.py collectstatic -l -c

I see "Deleting '...'" for each of the broken symlinks, and no corresponding "Linking '...'" lines. I would expect the broken symlinks to be gone. But they still exist.

Steps to reproduce:

ln -s asdfasd_something_that_doesnt_exist_fasdfasdf $STATIC_ROOT/broken_symlink
ls -l $STATIC_ROOT/broken_symlink
./manage.py collectstatic -l -c --noinput | grep broken_symlink
ls -l $STATIC_ROOT/broken_symlink

How could the broken symlinks get there in the first place? Answer: I'm using collectstatic -l and I deleted the original static files from my app, so the symlinks made last time still exist.

(Why do I care? Answer: this causes real trouble when used with WhiteNoise, because it can't find the original file and fails to start)

Change History (6)

comment:1 by Evan Heidtmann, 9 years ago

Description: modified (diff)

comment:2 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

The cause seems to be that FileSystemStorage.delete() checks if the path exists before trying to remove the file (for a broken symlink, this returns False) . If we can't find an elegant solution, we could document the behavior.

comment:3 by Claude Paroz, 9 years ago

Additionally to os.path.exists, I think we should also try os.lstat(path) which returns a stat_result content for a broken symlink (or OSError if the path doesn't exist at all).

comment:4 by Yusuke Miyazaki, 9 years ago

I sent a pull request: https://github.com/django/django/pull/5425
Please review it.

comment:5 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 0922bbf1:

Fixed #25346 -- Allowed collectstatic to delete broken symlinks.

comment:6 by Tim Graham <timograham@…>, 9 years ago

In 9039ff60:

[1.9.x] Fixed #25346 -- Allowed collectstatic to delete broken symlinks.

Backport of 0922bbf18d3ae8f37e1823df2dbc270d33334548 from master

Note: See TracTickets for help on using tickets.
Back to Top