How to Hardlink directories (in mojave)

Mac OSX specific forum
a.ross
User
User
Posts: 21
Joined: Tue Dec 08, 2009 12:50 am

How to Hardlink directories (in mojave)

Post 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
a.ross
User
User
Posts: 21
Joined: Tue Dec 08, 2009 12:50 am

Re: How to Hardlink directories (in mojave)

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to Hardlink directories (in mojave)

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
a.ross
User
User
Posts: 21
Joined: Tue Dec 08, 2009 12:50 am

Re: How to Hardlink directories (in mojave)

Post 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
Post Reply