Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch parent folders when editing a file #2382

Open
4 tasks done
elyahw opened this issue Aug 1, 2024 · 13 comments
Open
4 tasks done

Touch parent folders when editing a file #2382

elyahw opened this issue Aug 1, 2024 · 13 comments

Comments

@elyahw
Copy link
Contributor

elyahw commented Aug 1, 2024

⚠️ This issue respects the following points: ⚠️

  • This is a enhancement/feature request. Not a bug or question.
  • The topic is not already reported at Issues. (I've searched it).
  • Markor is up to date. See Releases for the latest version. Updates are available from F-Droid and GitHub.
  • The wanted feature/enhancement is not present in the latest development version (git master). (Please download and try the test version of Markor, named Marder. Don't worry; Markor and Marder appear as completely separate applications. You can install both side-by-side, and Markor's settings are not touched. If your desired feature is present, you don't need to open this issue. The change will be part of the next Markor update.)

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
Copy link
Owner

gsantner commented Aug 1, 2024 via email

@elyahw
Copy link
Contributor Author

elyahw commented Aug 1, 2024

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
Copy link
Owner

gsantner commented Aug 1, 2024

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
Copy link
Contributor Author

elyahw commented Aug 1, 2024

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
Copy link
Owner

gsantner commented Aug 1, 2024

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
Copy link
Contributor Author

elyahw commented Aug 2, 2024

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
Copy link
Collaborator

harshad1 commented Aug 4, 2024

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

@elyahw
Copy link
Contributor Author

elyahw commented Aug 15, 2024

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
Copy link
Collaborator

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
Copy link
Contributor Author

elyahw commented Aug 16, 2024

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
Copy link
Collaborator

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
Copy link
Contributor Author

elyahw commented Aug 31, 2024

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
Copy link
Contributor Author

elyahw commented Sep 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants