Skip to content

Do not write to read-only file (save) #2851

Closed

Description

@lionkmp

First thank you for this great program! And sorry to see you are overwhelmed with the issues. I can try to provide a patch to this if necessary and if you agree regarding the report.

Version, Operating system
CherryTree 1.6.2 on Debian 12
and the version that comes with Debian 13

Describe the bug
When the file is read-only for me (chmod 440) I can still write to it. Unless I disable backups.

To Reproduce
Steps to reproduce the behavior:

  1. chmod 440 your_file
  2. Open for editing
  3. Save
  4. File gets moved to backup and new file is created, totally irrespective of read-only mode
  5. Disabling backups solves that because then it attempts to write to the same file

Comparison to Geany and Vim

I tested behavior of Geany and Vim to see what happens.

  • Geany totally disallows saving to 440, regardless of backup mode on or off
  • Vim requires w! to overwrite, warns at opening, error on normal writing

I wanted to see if they create new INODEs like CherryTree, and they do:

Test files

lion@kmp:~/tmp/filetest$ ls -lai
összesen 24
10093403 drwxr-xr-x  2 lion lion 4096 May  7 08.51 .
 9961799 drwxr-xr-x 19 lion lion 4096 May  7 08.50 ..
10103861 -r--r--r--  1 lion lion   21 May  7 08.51 geany_ro.txt
10103858 -rw-r--r--  1 lion lion   23 May  7 08.51 geany_rw.txt
10093809 -r--r--r--  1 lion lion   21 May  7 08.50 vim_ro.txt
10103853 -rw-r--r--  1 lion lion   23 May  7 08.51 vim_rw.txt

After writing to them, with backup mode on:

  • Vim moves the original file to become backup, like CherryTree
  • Geany_rw results in totally new inode
lion@kmp:~/tmp/filetest$ ls -lai
összesen 36
10093403 drwxr-xr-x  2 lion lion 4096 May  7 09.00 .
 9961799 drwxr-xr-x 19 lion lion 4096 May  7 08.50 ..
10103861 -r--r--r--  1 lion lion   21 May  7 08.51 geany_ro.txt
10103889 -rw-r--r--  1 lion lion   30 May  7 08.59 geany_rw.txt
10103858 -rw-r--r--  1 lion lion  407 May  7 09.00 results.txt
10103887 -r--r--r--  1 lion lion   28 May  7 08.54 vim_ro.txt
10093809 -r--r--r--  1 lion lion   21 May  7 08.50 vim_ro.txt~
10103885 -rw-r--r--  1 lion lion   30 May  7 08.53 vim_rw.txt
10103853 -rw-r--r--  1 lion lion   23 May  7 08.51 vim_rw.txt~

Geany's temp folder was on a different partition, so cannot compare inode:

lion@kmp:~/tmp/filetest$ ls -lai /tmp | grep 'lion.*geany'
2097165 -rw-------  1 lion lion   30 May  7 08.59 geany_rw.txt.2026-05-07-08-59-31

When Geany temp dir is set to same partition, inode still different for the backup

before:
10103889 -rw-r--r--  1 lion lion   30 May  7 08.59 geany_rw.txt

after:
lion@kmp:~/tmp/filetest$ ls -lai .. | grep 'lion.*geany'
 9968693 -rw-------  1 lion lion           39 May  7 09.03 geany_rw.txt.2026-05-07-09-03-34
lion@kmp:~/tmp/filetest$ ls -lai geany_rw*
10103298 -rw-r--r-- 1 lion lion 39 May  7 09.03 geany_rw.txt

Test summary

I think VIM explicitly tests for write-ability of the file and handles this by alerting the user and explicitly disallowing the normal write. While Geany simply attempts to write to it and fails, and warns me that the file may be truncated. Vim's behavior is better. (Tested with vim-gtk3 on Debian 12.)

Reasoning

I have a main file on my main PC, and on my laptop I tend to add notes to it, but that's then lost. So I tried to make the file read-only to remind myself. (For now I turned off backups to solve this.)

Thank you in advance, and keep up the good work!

Activity

  1. giuspen commented on May 9, 2026

    @giuspen
    Owner

    Hello @lionkmp thanks for reporting this, it was an easy fix so I quickly implemented it, you can give it a try if you want in https://www.giuspen.net/cherrytree/#testing (only AppImage binary available for testing) I am planning to release a new version in about 10 days

  2. lionkmp commented on May 12, 2026

    @lionkmp
    Author

    @giuspen Thank you for the quick fix!
    I didn't try the test version, but I can see the change is small and looks cool, so that should solve it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions