question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Symbolic and hard links "broken" when saving files

See original GitHub issue

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

I have a few files which are either symbolic or hard links pointing to other files. Before I updated spyder from ~v.3 to the latest v.4.0.1 (from my anaconda distribution), if I modified and saved the symbolic/hard link, it also modified the other links pointing to the same file accordingly. However, with v.4.0.1 if I modify a link (symbolic or hard, actually it does not matter), the link is “broken”.

As an example, if I have a file test.py and a symbolic link in another directory also called test.py, if I open the sym link, update its content and then save it, it will no longer be a sym link, but instead a new python file called test.py. The same applies for hard links, where the link no longer exists after the update (typically stat test.py would show 2 links before saving, and 1 after).

From what I have tried, just opening the file without modifying it does not break the link, only when saving the link no longer exists.

Not sure if it’s a bug or the normal behaviour, but it definitely changed between ~v.3 and v.4.1.0.

What steps reproduce the problem?

  1. Create a python file test.py and fill it with some lines of code
  2. Make a symbolic/hard link pointing to test.py, (e.g. ln -s test.py test2.py)
  3. You can check if it worked with ls -l test2.py (you should see at the end of the line something like test2.py -> test.py)
  4. Open test2.py with spyder, mofidy it and save it
  5. Check the sym link again with ls -l test2.py (you should only see test2.py at the end of the line)

What is the expected output? What do you see instead?

Expected output would be that symbolic or hard links would not be broken, and that modifying one link would modify the content of all the other links pointing to the same file.

Versions

  • Spyder version: 4.0.1
  • Python version: 3.7.6
  • Qt version: 5.14.1
  • PyQt version: 5.14.1
  • Operating System name/version: Linux 5.3.0-40-generic (Ubuntu 19.10)

Dependencies

atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.12.0 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
keyring                      :  None (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.7 (OK)
xdg >=0.26                   :  0.26 (OK)
zmq >=17                     :  18.1.1 (OK)
qdarkstyle >=2.7             :  2.8 (OK)
qtawesome >=0.5.7            :  0.6.1 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.9.3 (OK)
sphinx >=0.6.6               :  2.4.0 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.15 (OK)
matplotlib >=2.0.0           :  3.1.3 (OK)
numpy >=1.7                  :  1.18.1 (OK)
pandas >=0.13.1              :  1.0.1 (OK)
scipy >=0.17.0               :  1.4.1 (OK)
sympy >=0.7.3                :  1.5.1 (OK)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dalthvizcommented, Mar 4, 2020

Note: Probably we need to resolve symlinks when saving. We can use something like: os.readlink, os.path.realpath or pathlib.Path.resolve

1reaction
ccordoba12commented, Mar 4, 2020

Edit: I was checking and regarding files saving I did a fix but it was to preserve file permission when saving - PR #9550

Ok, that was it!


@dalthviz, I think the usage of atomicwrites makes no possible to use symlinks, so we should forbid opening symlinks in the editor, even if that’s a regression with respect to Spyder 3.

So please investigate first the possibility of working with symlinks and atomicwrites. If that’s not possible, please add a warning message saying that it’s not possible to open symlinks anymore to guarantee that files are saved correctly to disk.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hard Links Created in Windows Not Updated After Using MS ...
I notice that when a hard link is created from a file, and when that hard link is opened using an MS-Office program...
Read more >
What is the difference between symbolic and hard links?
Symbolic links, or "symlinks" work a little like Windows shortcuts. The contents of a symlink are a pointer to the real location of...
Read more >
Hard links and Symbolic links — A comparison - Medium
What will break a symbolic link is when the original file is moved to a different file or deleted. Moving the original file...
Read more >
Can hard links get broken? - Stack Overflow
This can happen if the original file ( ~/work/genDocs/bibs/SKM.bib ) is recreated instead of being modified in-place.
Read more >
Understanding NTFS Hard Links, Junctions and Symbolic Links
Although a hard link is essentially a mirrored copy of the target file that it is pointing to, no additional hard drive space...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found