Most of Apps break hardlinks system!

If it doesn't relate to Debian, but you still want to share it, please do it here

Most of Apps break hardlinks system!

Postby bester69 » 2018-12-19 11:20

Hi,

Do you know why most of apps cant work with hardlinks without breaking the hardlink?..Shouldn't kernel be able to manage this at low level?. I find it extrange :shock:

There are some apps can manage hardlinks like libreoffice, most of text editors, but when working with images or movies, I saw those programs create a new file with the source breaking the hardlink (gimp, jpegoptim, etc)..

For example, I couldnt apply jpegoptim to hardlink files, without using tweaking script.:
find ./ -name "*.jpg" -exec jpegoptim -S70 "{}" \;
>>> This sentence break all hardlinks when recompressing image files.

For example, To using GImp with a hardlink we would need to apply a script code like this.:
Code: Select all
#!/bin/sh
#
cp $1 $2
gimp $2
cat $2 > $1
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1413
Joined: 2015-04-02 13:15

Re: Most of Apps break hardlinks system!

Postby bw123 » 2018-12-19 14:19

bester69 wrote:...
Do you know why most of apps cant work with hardlinks without breaking the hardlink?..Shouldn't kernel be able to manage this at low level?. I find it extrange :shock:
...


I don't know why, but I have noticed the same in many cases. I'm not sure I'd say it was "most apps," but yeah most windows/cross platform apps that have been ported to linux seem to do this... and they do it silently. It is very annoying.

I think it might be because one way to update/overwrite a file is to delete it and replace it with a new file. Also, it seems many programmers don't understand linux from the user point of view.

Editing a file as a tmp and moving it over the link has the same result. Some aps have an "edit in place" flag, or a setting to follow symlinks, but I don't think that is consistent feature.

Code: Select all
$ echo "this is foofile" > foofile
$ ln foofile foolink
$ cat foolink
this is foofile
$ echo "this is foofiletmp" > foofiletmp
$ mv foofiletmp foolink
$ cat foolink
this is foofiletmp
$ cat foofile
this is foofile
User avatar
bw123
 
Posts: 3787
Joined: 2011-05-09 06:02

Re: Most of Apps break hardlinks system!

Postby bester69 » 2018-12-19 15:25

bw123 wrote:
bester69 wrote:...
Do you know why most of apps cant work with hardlinks without breaking the hardlink?..Shouldn't kernel be able to manage this at low level?. I find it extrange :shock:
...


I don't know why, but I have noticed the same in many cases. I'm not sure I'd say it was "most apps," but yeah most windows/cross platform apps that have been ported to linux seem to do this... and they do it silently. It is very annoying.
..

yeah, they do it silently... I have litle space in disk and love hardlinks to work with.


For example, for using "jpegoptim" with "find" I had to create a wrapper script to proccess operations and keep unbroken hardlinks.


Example.:
Code: Select all
#!/bin/bash
#
find . -name "*.jpg" -maxdepth 1  -exec /home/user/scripts/jpegminfind.sh  "{}" \;

jpegminfind.sh
Code: Select all
#!/bin/bash
#
TAG="$1"

cp "$TAG" "$TAG".bak
jpegoptim -S70  "$TAG".bak
cat "$TAG".bak >"$TAG"
rm "$TAG".bak


We will have to be carefully :?
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1413
Joined: 2015-04-02 13:15

Re: Most of Apps break hardlinks system!

Postby bw123 » 2018-12-21 19:21

bester69, do you think there might be a way to tweak the fs to change this? I don't think it's a kernel issue, probably something in the way the filesystem presents the file to the thing opening it? Does every app opening a file need to test for hard link and warn, or test on save? Most apps ask, "Do you want to replace?" but they don't mention that you will replace a link with a file.

Heck yeah, VERY annoying.
User avatar
bw123
 
Posts: 3787
Joined: 2011-05-09 06:02

Re: Most of Apps break hardlinks system!

Postby bester69 » 2018-12-21 19:58

bw123 wrote:bester69, do you think there might be a way to tweak the fs to change this? I don't think it's a kernel issue, probably something in the way the filesystem presents the file to the thing opening it? Does every app opening a file need to test for hard link and warn, or test on save? Most apps ask, "Do you want to replace?" but they don't mention that you will replace a link with a file.

Heck yeah, VERY annoying.


You're right; we need a smart solution here, I guess Filesystem and kernel should work together to manage an intelligence solution.

Furthermore, Graphicals desktop should add some kind of shortcut symbol/arrow to show they're hardlinks.. I think Torvalds might no be very pro hardlinks ways.

:)
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1413
Joined: 2015-04-02 13:15

Re: Most of Apps break hardlinks system!

Postby p.H » 2018-12-22 09:45

bester69 wrote:Filesystem and kernel should work together to manage an intelligence solution.

This is neither a kernel nor filesystem issue. It is a userland issue.
When userland asks the kernel to :
- open file A in read mode
- create/open file B in write mode
- read into A
- write into B
- move/rename B to A (which implies removing A)

How should the kernel figure out that it should actually copy the contents of B into A and remove B instead of the expected specified behaviour ? The userland should explicitly ask for this if this is what it wants. Hardlinks and symlinks are basic Unix filesystem features. Userland has to deal with them.
p.H
 
Posts: 1046
Joined: 2017-09-17 07:12


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 13 guests

fashionable