Page 1 of 1

How to Hardlink directories (in mojave)

Posted: Fri Jan 13, 2023 8:10 am
by a.ross
So i found this on-line is there an easy way to do this in PB, the terminal command "ln" won't do it as you can only symbolic link directories

Code: Select all

#include <unistd.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
 if (argc != 3) {
  fprintf(stderr,"Use: hlink <src_dir> <target_dir>\n");
  return 1;
 }
 int ret = link(argv[1],argv[2]);
 if (ret != 0)
  perror("link");
 return ret;
}
It seems the "link" command is the one there using, but can you import that into PB?

Cheers
Andrew

Also, thanks, any help would be appreciated

Also Also I guess i could just compile this, but would like it to run purely run in PB

Re: How to Hardlink directories (in mojave)

Posted: Sat Jan 14, 2023 4:36 am
by a.ross
Ok I've just decided to just hardlink each file individually by calling the terminal ln command, this will get me want i need without needing to elevate privileges.

Re: How to Hardlink directories (in mojave)

Posted: Sat Jan 14, 2023 11:50 am
by mk-soft
I don't know what the programme is supposed to do...

Code: Select all


Procedure Main()
  Protected r1, *arg1, *arg2
  If CountProgramParameters() <> 3
    Debug "Use: hlink <src_dir> <target_dir>\n"
    ProcedureReturn 1
  Else
    *arg1 = Ascii(ProgramParameter(1))
    *arg2 = Ascii(ProgramParameter(2))
    r1 = link_(*arg1, *arg2)
    If r1 <> 0
      Debug "link"
    EndIf
    FreeMemory(*arg1)
    FreeMemory(*arg2)
    ProcedureReturn r1
  EndIf
EndProcedure

a = Main()
Debug a

Re: How to Hardlink directories (in mojave)

Posted: Sun Jan 15, 2023 4:12 am
by a.ross
Perfect, That works.
I did discover that APFS formatted drives just don't support Hardlinking directories but Mac OS Extended drives seem to work fine I've (rather poorly) added unlink for the procedure i wanted.

Code: Select all

Procedure hlink(Source$,Target$) ; pass blank target to unlink
  Protected r1, *arg1, *arg2
  *arg1 = Ascii(Source$)
  If Target$<>""
    *arg2 = Ascii(Target$)
    r1 = link_(*arg1, *arg2)
  Else
    r1 = unlink_(*arg1)
  EndIf
  If r1 => 0
    Debug "link OK"
  Else
    Debug "Link failed"
  EndIf
  FreeMemory(*arg1)
  If Target$<>""
    FreeMemory(*arg2)
  EndIf
  ProcedureReturn r1
EndProcedure
Thank you so much, didn't realise all i needed to do was so link_
Cheers
a.ross