Opened 11 years ago

Closed 11 years ago

#20780 closed Bug (fixed)

collectstatic --link causes IOError when dangling symlink exists

Reported by: Diederik van der Boor Owned by: John Giannelos
Component: contrib.staticfiles Version: 1.5
Severity: Normal Keywords:
Cc: John Giannelos Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a symlink file already exists, but it's source was moved/renamed, collectstatic ends with an IOError.

Here is a trackback example:

Linking '/srv/www/virtualenvs/demo.example.org/src/django-filebrowser-no-grappelli-django14/filebrowser/static/filebrowser/js/FB_TinyMCE.js'
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
    collected = self.collect()
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 113, in collect
    handler(path, prefixed_path, storage)
  File "/srv/www/virtualenvs/demo.example.org/lib/python2.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 275, in link_file
    os.symlink(source_path, full_path)
OSError: [Errno 17] File exists

I switched moduled here, hence the symlinks of the previous "filebrowser" were still there, but no longer pointed to an existing file.
The same also happens when one reorganized the project layout, while.

How to reproduce:

  • Have a project with 1 app.
  • run ./manage.py collectstatic --link
  • Rename that app, or move it to a sub package.
  • run ./manage.py collectstatic --link again.

Attachments (3)

Change History (13)

comment:1 by John Giannelos, 11 years ago

Cc: John Giannelos added
Owner: changed from nobody to John Giannelos
Status: newassigned

comment:2 by John Giannelos, 11 years ago

Has patch: set

comment:3 by wim@…, 11 years ago

Triage Stage: UnreviewedAccepted

Hehe I ran into the same issue not too long ago, when I too was dealing with a filebrowser.

comment:4 by wim@…, 11 years ago

Hi John, does your patch not leave the broken link, in stead of replacing it by the new one?

comment:5 by Tim Graham, 11 years ago

Easy pickings: unset

comment:6 by John Giannelos, 11 years ago

Hi, sorry for not showing a sign of progress after that long time.
Yes, the patch I had sent left the broken link instead of replacing it.
I am attaching an updated patch that removes the dangling symlink first.

Last edited 11 years ago by John Giannelos (previous) (diff)

comment:7 by Vajrasky Kok, 11 years ago

Needs tests: set

comment:8 by John Giannelos, 11 years ago

Needs tests: unset

comment:9 by John Giannelos, 11 years ago

Updated patch with test.

Last edited 11 years ago by John Giannelos (previous) (diff)

comment:10 by Jannis Leidel <jannis@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In f90be002d9d3c10b87c74741986e2cbf9f2b858e:

Fixed #20780 -- Get rid of stale symlinks when using collectstatic.

Thanks to John Giannelos for the initial patch.

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