ulinks.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "rar.hpp"
  2. bool ExtractLink(ComprDataIO &DataIO,Archive &Arc,const char *LinkName,uint &LinkCRC,bool Create)
  3. {
  4. #if defined(SAVE_LINKS) && defined(_UNIX)
  5. char LinkTarget[NM];
  6. if (IsLink(Arc.NewLhd.FileAttr))
  7. {
  8. int DataSize=Min(Arc.NewLhd.PackSize,sizeof(LinkTarget)-1);
  9. DataIO.UnpRead((byte *)LinkTarget,DataSize);
  10. LinkTarget[DataSize]=0;
  11. if (Create)
  12. {
  13. CreatePath(LinkName,NULL,true);
  14. if (symlink(LinkTarget,LinkName)==-1) // Error.
  15. if (errno==EEXIST)
  16. Log(Arc.FileName,St(MSymLinkExists),LinkName);
  17. else
  18. {
  19. Log(Arc.FileName,St(MErrCreateLnk),LinkName);
  20. ErrHandler.SetErrorCode(WARNING);
  21. }
  22. // We do not set time of created symlink, because utime changes
  23. // time of link target and lutimes is not available on all Linux
  24. // systems at the moment of writing this code.
  25. }
  26. int NameSize=Min(DataSize,strlen(LinkTarget));
  27. LinkCRC=CRC(0xffffffff,LinkTarget,NameSize);
  28. return(true);
  29. }
  30. #endif
  31. return(false);
  32. }