hardlinks.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. bool ExtractHardlink(CommandData *Cmd,wchar *NameNew,wchar *NameExisting,size_t NameExistingSize)
  2. {
  3. SlashToNative(NameExisting,NameExisting,NameExistingSize); // Not needed for RAR 5.1+ archives.
  4. if (!FileExist(NameExisting))
  5. {
  6. uiMsg(UIERROR_HLINKCREATE,NameNew);
  7. uiMsg(UIERROR_NOLINKTARGET);
  8. ErrHandler.SetErrorCode(RARX_CREATE);
  9. return false;
  10. }
  11. CreatePath(NameNew,true,Cmd->DisableNames);
  12. #ifdef _WIN_ALL
  13. bool Success=CreateHardLink(NameNew,NameExisting,NULL)!=0;
  14. if (!Success)
  15. {
  16. uiMsg(UIERROR_HLINKCREATE,NameNew);
  17. ErrHandler.SysErrMsg();
  18. ErrHandler.SetErrorCode(RARX_CREATE);
  19. }
  20. return Success;
  21. #elif defined(_UNIX)
  22. char NameExistingA[NM],NameNewA[NM];
  23. WideToChar(NameExisting,NameExistingA,ASIZE(NameExistingA));
  24. WideToChar(NameNew,NameNewA,ASIZE(NameNewA));
  25. bool Success=link(NameExistingA,NameNewA)==0;
  26. if (!Success)
  27. {
  28. uiMsg(UIERROR_HLINKCREATE,NameNew);
  29. ErrHandler.SysErrMsg();
  30. ErrHandler.SetErrorCode(RARX_CREATE);
  31. }
  32. return Success;
  33. #else
  34. return false;
  35. #endif
  36. }