MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / ExtractUnixOwner20

Function ExtractUnixOwner20

Libraries/unrar/uowners.cpp:3–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1
2
3void ExtractUnixOwner20(Archive &Arc,const wchar *FileName)
4{
5 char NameA[NM];
6 WideToChar(FileName,NameA,ASIZE(NameA));
7
8 if (Arc.BrokenHeader)
9 {
10 uiMsg(UIERROR_UOWNERBROKEN,Arc.FileName,FileName);
11 ErrHandler.SetErrorCode(RARX_CRC);
12 return;
13 }
14
15 struct passwd *pw;
16 errno=0; // Required by getpwnam specification if we need to check errno.
17 if ((pw=getpwnam(Arc.UOHead.OwnerName))==NULL)
18 {
19 uiMsg(UIERROR_UOWNERGETOWNERID,Arc.FileName,GetWide(Arc.UOHead.OwnerName));
20 ErrHandler.SysErrMsg();
21 ErrHandler.SetErrorCode(RARX_WARNING);
22 return;
23 }
24 uid_t OwnerID=pw->pw_uid;
25
26 struct group *gr;
27 errno=0; // Required by getgrnam specification if we need to check errno.
28 if ((gr=getgrnam(Arc.UOHead.GroupName))==NULL)
29 {
30 uiMsg(UIERROR_UOWNERGETGROUPID,Arc.FileName,GetWide(Arc.UOHead.GroupName));
31 ErrHandler.SysErrMsg();
32 ErrHandler.SetErrorCode(RARX_CRC);
33 return;
34 }
35 uint Attr=GetFileAttr(FileName);
36 gid_t GroupID=gr->gr_gid;
37#if defined(SAVE_LINKS) && !defined(_APPLE)
38 if (lchown(NameA,OwnerID,GroupID)!=0)
39#else
40 if (chown(NameA,OwnerID,GroupID)!=0)
41#endif
42 {
43 uiMsg(UIERROR_UOWNERSET,Arc.FileName,FileName);
44 ErrHandler.SetErrorCode(RARX_CREATE);
45 }
46 SetFileAttr(FileName,Attr);
47}
48
49
50void ExtractUnixOwner30(Archive &Arc,const wchar *FileName)

Callers 1

SetExtraInfo20Function · 0.85

Calls 7

WideToCharFunction · 0.85
uiMsgFunction · 0.85
GetWideFunction · 0.85
GetFileAttrFunction · 0.85
SetFileAttrFunction · 0.85
SetErrorCodeMethod · 0.80
SysErrMsgMethod · 0.80

Tested by

no test coverage detected