Page 1 of 1

Failed to hardlink when --action=duplicate

Posted: 19 May 2019, 21:53
by queimadus
I think I may have found a bug when the action is set to duplicate and the underlying OS doesn't fully support for the first approach.

After digging through the code, I saw that when the action is set to "duplicate" it will try to "clone", if that fails fallback to "duplicate" and if that fails, fallback to "copy".

The "clone" option makes use of "cp --reflink" which apparently my OS does not support (Inappropriate ioctl for device). That alone logs an error but instead of fallbacking to "duplicate" it goes straight to a "copy". (I know duplicate works because that's how I fixed my setup, and it now correctly hardlinks files)

I didn't get much into why it skipped the second fallback, I think when the "cp --reflink" fails, it still creates an empty target file which may interfere with the duplicate fallback.

PS: Running "Linux vero 3.14.29-143-osmc #1 SMP osmc-ccachefix aarch64" while using the amc script

Re: Failed to hardlink when --action=duplicate

Posted: 20 May 2019, 08:06
by rednoah
Here's how it works:
1. Try clone / reflink
2. Try hardlink
3. Try copy

If clone doesn't work, then it will hardlink. If hardlink doesn't work, it will copy.

:idea: Debug logging will give you more information: viewtopic.php?f=3&t=3913

queimadus wrote:
19 May 2019, 21:53
I think when the "cp --reflink" fails, it still creates an empty target file which may interfere with the
Please confirm that cp --reflink indeed creates an empty target file. That would be pretty stupid cp behaviour. But if that's indeed the case, then I'll remove the clone attempt altogether.

Re: Failed to hardlink when --action=duplicate

Posted: 20 May 2019, 11:32
by queimadus
Seems like it does.

Code: Select all

[ [email protected] /tmp/test ]$ ls                                                                                                                                                                                                                                          
[ [email protected] /tmp/test ]$ echo hello > foo                                                                                                                                                                                                                            
[ [email protected] /tmp/test ]$ cp --reflink foo bar                                                                                                                                                                                                                        
cp: failed to clone 'bar' from 'foo': Inappropriate ioctl for device
[ [email protected] /tmp/test ]$ ls                                                                                                                                                                                                                                          
bar  foo
[ [email protected] /tmp/test ]$ cat bar                                                                                                                                                                                                                                     
[ [email protected] /tmp/test ]$ cat foo                                                                                                                                                                                                                                     
hello

Re: Failed to hardlink when --action=duplicate

Posted: 20 May 2019, 11:35
by rednoah
Noted. Will remove clone attempt from the duplicate action.

Re: Failed to hardlink when --action=duplicate

Posted: 09 Aug 2019, 11:20
by rednoah
I've updated the code to:

Code: Select all

1. Try hardlink
2. Try clonefile (via cp -c) / reflink (cp --reflink=auto)
3. Try physical copy
:idea: To make sure we don't create empty files, 2. Try clonefile / reflink now uses cp --reflink=auto, so on Linux the cp call will implicitly take care of copying files if necessary.

:idea: @since r6569