gsantner / markor

Text editor - Notes & ToDo (for Android) - Markdown, todo.txt, plaintext, math, ..
https://github.com/gsantner/markor/discussions/2269
Other
3.82k stars 365 forks source link

Touch parent folders when editing a file #2382

Open elyahw opened 3 months ago

elyahw commented 3 months ago

⚠️ This issue respects the following points: ⚠️

Description

  1. Currently, when sorting folders first option is turned off, when opening one of the folders and editing one of the notes inside:
  2. The file is touched (modification date is updated). But the folder is not touched, its modification date remains in the past.
  3. This is a problem because from the main menu, it is not possible to tell which folder was edited last.

Information

Android version: 13 Device: Pixel a5 App Version: 2.12.5

Source

GitHub Releases

Format / File type

Not specific

Additional info / Log

-
gsantner commented 3 months ago

I'm not sure if I understand right, but it might be just how the filesystem used for that folder works.

Changing a file in a folder not always leads to a timestamp change in the parent director(ies). And Markor only reads out filesystem metadata.

This is a problem because from the main menu, it is not possible to tell which folder was edited last.

Correct, you may not put too much relevance in what timestamps directories have. But thats regardless of what software you use.

elyahw commented 3 months ago

Yes possibly. But is not it possible that we initiate a manual touch operation on the folder? I can think of no reason why this could be dangerous or should not be done.

For example if markor home folder is /sd_card/Documents/markor/ If the file ./markor/Blog/posts/subject.txt is edited, both ./markor/Blog/ and ./markor/Blog/posts/ folders should be touched.

Correct, you may not put too much relevance in what timestamps directories have

True, I would agree with you about any other folder outside of the main markor directory. But the folders inside the markor directory are dedicated for markor and for storing notes. So in a sense they are local, and are used solely for organising notes, mainly by the markor app.

gsantner commented 3 months ago

Does any other editor or alike do that - touching all parent directories?

I'm not aware of that at least and it may have unwanted side effects (i.e. with sync clients, permissions etc).

elyahw commented 3 months ago

all parent directories

You are right. I tested two browsers on linux dolphin and nautilus; both touch only the immediate parent folder, but not beyond. I think in the case of markor this would be sufficient.

gsantner commented 3 months ago

I don't check the code, but I assume there is no statement in the browsers to do explicitly touch a parent folder. Rather something how the OS or filesystem behaves in that specific case.

The problem is also that there is not always \<the one and only parent>. You can have countless of symlinks if the filesystem supports it and touching one won't affect the other. (not even with absolute filepaths you can be sure [bind mounts])

image

I understand why you are asking and want to have such a change, but humbly said preferable it's not added. The file handling is very complex and I don't want additional rules if they are not necessary. This is something the filesystem and OS should take care of and do their default handling in case of file writing.

elyahw commented 3 months ago

Alright. I figured it out:

It seems like Android only touches the immediate parent folder if: 1. either a new file has been created inside, or 2. an existing file gets renamed. It does not touch the parent folder if an existing file is touched/edited. This applies not only to markor, but also to other Android file browsers.


Regarding what you said, certainly, this is something that should be automatically handled by Android filesystem. But please note that:

  1. How many people use symbolic links on Android? (I have never used it before) And markor does not provide the ability to create them, nor there is a need for such complexity.
  2. Symlinks are not folders, but files in themselves. If the modification date of the file is changed, the symbolic link should not be affected, this is logical I think.

Perhaps it is possible to make an extra system call to initiate parent folder touching?

harshad1 commented 3 months ago

You could just write an external script to do this with termux

elyahw commented 2 months ago

I would like to program this feature, I would appreciate any help as I have little knowledge about Android:

I would suggest putting a check in side the function which writes changes to a file, that checks:

If the file exists in a folder within the Markor home folder, touch the immediate parent folder.

Otherwise do nothing.

Is this a sound strategy? And can anyone suggest which files I should edit? What remains is the system call to touch the folder, I have no idea if such a thing exists but I'll start researching it..

harshad1 commented 2 months ago

I think this should not be done.

Touching the parent folder is when I file is edited is not standard filesystem behavior. Imo this should be left to the filesystem.

There could well be side effects - sync apps breaking etc.

elyahw commented 2 months ago

I understand your fears. But please allow me to challenge you:

Are there any side effects when a new file is created (the parent folder is automatically touched -by the filesystem-)?

Are there any side effects when a file is renamed (the parent folder is automatically touched)?

In the same way, there shouldn't be any danger if we trigger whatever system mechanism is being triggered in the two cases above.

I think this is simply a design choice that Android designers made, perhaps it has its useful cases. But for us, a notes program, you want to see the notes/folders you last modified near the top.

Consider this use case:

I have a folder "Family", containing 10 notes, each one named afte a family member. I edit them often. After a couple of weeks this folder will be pushed down to the bottom of my notes (despite it being the most edited folder). And I will have to scroll down searching for it every time.

If you are still unwilling to integrate such a behaviour, I will close this issue and ask it as a question in the discussion.. Thanks very much.

harshad1 commented 2 months ago

I think this is simply a design choice that Android designers made, perhaps it has its useful cases

The Ext4 fs on my laptop does not update the folder mod time when a child file is modified. Only when a child file is created / deleted.

Fundamentally, this is @gsantner's decision to make, but IMO we should not touch parent folder(s) when a file is saved.

elyahw commented 2 months ago

I have solved it by editing the function public boolean saveDocument(final boolean forceSaveEmpty) inside the file DocumentEditAndViewFragment.java so that it contains:

...
if (!_document.isContentSame(text))
{
    // Touch parent folder on edit
    File ff = _document.getFile();
    String ppath = "";
    ppath = ff.getAbsolutePath();

    File parentFolder = ff.getParentFile();
    long currentTime = System.currentTimeMillis();
    parentFolder.setLastModified(currentTime);

    ... rest of code ...
elyahw commented 2 months ago

I have been using it now daily for more than a week without any issues. If this simple code is something you would merge, I would happily create a MR.