Komodo / KomodoEdit

Komodo Edit is a fast and free multi-language code editor. Written in JS, Python, C++ and based on the Mozilla platform.
http://www.komodoide.com/komodo-edit
Other
2.14k stars 299 forks source link

Can't save if new file is smaller than old one. #3865

Closed ghost closed 4 years ago

ghost commented 4 years ago

Short Summary

When i try to save any file that's smaller than the old one the last characters repeat to keep the same file size .

Steps to Reproduce

Enter 123456789 in editor Erase 6789 Save

Expected results

Saved file contains 12345

Actual results

Saved file contains

12345
6789

Platform Information

Komodo Edit Latest commit d007808

Debian Buster https://github.com/Laniture/Komodo-Build-Script

th3coop commented 4 years ago

I can't reproduce this.

@Laniture can you try this in safe mode? Help menu > Troubleshooting > Restart in Safe-Mode

There's nothing significant in the logs that would tells us what's going on here.

ghost commented 4 years ago

@th3coop Sorry i should have specified that i am using a build from source.

Made a build script for you. https://github.com/Laniture/Komodo-Build-Script

th3coop commented 4 years ago

@Laniture anything in the logs? Help > Troubleshooting > View Log file

ghost commented 4 years ago

Mozilla build log (13k lines). https://file.io/nQ5oTAv7

Komodo log. https://ghostbin.tech/paste/c86uk/raw

The package from your website works fine. But i get the issue even when i build it in your docker then bk package aspackage and run it outside.

Dockerfile https://ghostbin.tech/paste/dkrxv/raw

ghost commented 4 years ago

I found the code that's causing the problem. It seems like the official build have this difference compared to the repo. https://github.com/Komodo/KomodoEdit/blob/master/src/views/koDocument.py

@@ -1721,7 +1721,7 @@ INSTALLDIR/lib/mozilla/components/koDocument.py
                 self.doAutoSave()

             try:
+                self.file.open('wb+')
-                self.file.open('rb+')
                 try:
                     self.file.write(data)
                 finally:

When i make this change to my local build the issue is gone.

th3coop commented 4 years ago

@Laniture the rb+ code is released and no one else if having an issue. Can you please try installing the official release rather than a local build and try to reproduce the issue?

ghost commented 4 years ago

@th3coop i can reproduce the issue with the official release.

wget https://downloads.activestate.com/Komodo/releases/12.0.1/Komodo-Edit-12.0.1-18441-linux-x86_64.tar.gz
tar -xvzf Komodo-Edit-12.0.1-18441-linux-x86_64.tar.gz
cd Komodo-Edit-12.0.1-18441-linux-x86_64/INSTALLDIR/bin/
./komodo # No issue

# Replace wb+ with rb+ to match repo and my build
sed -i "s/self.file.open('wb+')/self.file.open('rb+')/" ../lib/mozilla/components/koDocument.py
./komodo # Issue
th3coop commented 4 years ago

Ahh this is released in a nightly. That's why no one is hitting it. That change was for https://github.com/Komodo/KomodoEdit/issues/337. I see my mistake though. w mode always truncates the file. r opens the file with the file pointer at the start of the file and leaves the existing content. We're just overwriting the beginning of the file.

I've revert the change. I investigated options to make both issues work but due to how Komodo inherited objects through XPCOM. I can't actually get at the opened file to manipulate it (truncate it manually in this case). We were relying on w mode to truncate it before which causes #337.

PRs are welcome on #337.

th3coop commented 4 years ago

This will be fixed in a nightly tomorrow and if you pull in master you'll get the fix @Laniture.

Thanks for reporting.