ho-tex / pdfcrop

pdfcrop perl utility
LaTeX Project Public License v1.3c
25 stars 6 forks source link

Permission error occurs in Windows OS #16

Open muneue-suwa opened 1 year ago

muneue-suwa commented 1 year ago

Permission error occurs in Windows OS as follows.

> pdfcrop.exe .\figures.pdf
PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.
!!! Error: Link from `.\figures.pdf' to `tmp-pdfcrop-25824-img.pdf' failed (Operation not permitted/クライアントは要求された特権を保有していません。)!
C:\texlive\2022\bin\win32\runscript.tlu:915: command failed with exit code 2:
perl.exe c:\texlive\2022\texmf-dist\scripts\pdfcrop\pdfcrop.pl .\figures.pdf 

I am using

I think the symlink command in l.711 is the cause of the error. Because Windows OS required administrator permission to create symbolic links.

It seems that pdfcrop.pl has the feature to switch symlink command to copy command using $symlink_exists. However, I guess the feature does not work well. Therefore, I suggest we should switch to copy command in Windows OS regardless of $symlink_exists.

u-fischer commented 1 year ago

I can't reproduce the problem on my Win10 22H2. Why is $symlink_exists true on your system? Are you using an external perl? Or is it specific to Win Pro?

muneue-suwa commented 1 year ago

Why is $symlink_exists true on your system?

I have no idea. Let me know which variable I should confirm, if you possible.

Are you using an external perl?

I do not use external perl and just used pdfcrop command. (I did not install perl to my PC)

Or is it specific to Win Pro?

I do not have Windows Home PC. I'll ask my friend who has it in a few days.

muneue-suwa commented 1 year ago

Certainly, this error does not occur in my friend's PC which is Windows 11 Home 21H2. There is a high probability that the error are specific to Windows Pro.

endereyewxy commented 10 months ago

The issue still exists for build 22H2. A dirty workaround is to allow any users to create symlinks via the group policy editor.

https://stackoverflow.com/questions/58038683/allow-mklink-for-a-non-admin-user

davidcarlisle commented 10 months ago

@endereye probably changing

    my $symlink_exists = eval {
        local $SIG{'__DIE__'};
        symlink("", "");
        1;
    };

to

  my $symlink_exists = 0;
  unless ($win) {
   $symlink_exists =eval {
        local $SIG{'__DIE__'};
        symlink("", "");
        1;
    };
}

fixes it (untested) but it would be good to know how symlink_exists gets set to true in systems where the user doesn't have permission to generate a symlink as a more logically correct test would be to fix the $symlink_exists =eval { rather than just avoiding windows.