Opened 3 years ago

Closed 3 years ago

#20780 closed Bug (fixed)

collectstatic --link causes IOError when dangling symlink exists

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


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/'
Traceback (most recent call last):
  File "", line 10, in <module>
  File "/srv/www/virtualenvs/", line 443, in execute_from_command_line
  File "/srv/www/virtualenvs/", line 382, in execute
  File "/srv/www/virtualenvs/", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/srv/www/virtualenvs/", line 232, in execute
    output = self.handle(*args, **options)
  File "/srv/www/virtualenvs/", line 371, in handle
    return self.handle_noargs(**options)
  File "/srv/www/virtualenvs/", line 163, in handle_noargs
    collected = self.collect()
  File "/srv/www/virtualenvs/", line 113, in collect
    handler(path, prefixed_path, storage)
  File "/srv/www/virtualenvs/", 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 ./ collectstatic --link
  • Rename that app, or move it to a sub package.
  • run ./ collectstatic --link again.

Change History (13)

comment:1 Changed 3 years ago by johngian

  • Cc johngian added
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to johngian
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 3 years ago by johngian

  • Has patch set

comment:3 Changed 3 years ago by wim@…

  • Triage Stage changed from Unreviewed to Accepted

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

comment:4 Changed 3 years ago by wim@…

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

comment:5 Changed 3 years ago by timo

  • Easy pickings unset

comment:6 Changed 3 years ago by johngian

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 3 years ago by johngian (previous) (diff)

comment:7 Changed 3 years ago by vajrasky

  • Needs tests set

comment:8 Changed 3 years ago by johngian

  • Needs tests unset

comment:9 Changed 3 years ago by johngian

Updated patch with tests.

Version 0, edited 3 years ago by johngian (next)

comment:10 Changed 3 years ago by Jannis Leidel <jannis@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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