aboutsummaryrefslogtreecommitdiff
path: root/lib/UnrarXLib/ulinks.cpp
blob: 49d322226c3d2230b7c0e69933ced05f54bbf029 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "rar.hpp"
#include "Util.h"
#include "utils/URIUtils.h"


int ExtractLink(ComprDataIO &DataIO,Archive &Arc,char *DestName,uint &LinkCRC,bool Create)
{
#if defined(SAVE_LINKS) && defined(_UNIX)
  char FileName[NM];
  if (IsLink(Arc.NewLhd.FileAttr))
  {
    uint DataSize=Min(Arc.NewLhd.PackSize,sizeof(FileName)-1);
    DataIO.UnpRead((byte *)FileName,DataSize);
    FileName[DataSize]=0;
    if (Create)
    {
      CStdString strPath;
      URIUtils::GetDirectory(DestName,strPath);
      CUtil::CreateDirectoryEx(strPath);
      if (symlink(FileName,DestName)==-1)
      {
        if (errno==EEXIST)
          Log(Arc.FileName,St(MSymLinkExists),DestName);
        else
        {
          Log(Arc.FileName,St(MErrCreateLnk),DestName);
          ErrHandler.SetErrorCode(WARNING);
        }
      }
    }
    int NameSize=Min(DataSize,strlen(FileName));
    LinkCRC=CRC(0xffffffff,FileName,NameSize);    return(1);
  }
#endif
  return(0);
}