| 1 | #include "rar.hpp" |
| 2 | |
| 3 | MKDIR_CODE MakeDir(const wchar *Name,bool SetAttr,uint Attr) |
| 4 | { |
| 5 | #ifdef _WIN_ALL |
| 6 | // Windows automatically removes dots and spaces in the end of directory |
| 7 | // name. So we detect such names and process them with \\?\ prefix. |
| 8 | wchar *LastChar=PointToLastChar(Name); |
| 9 | bool Special=*LastChar=='.' || *LastChar==' '; |
| 10 | BOOL RetCode=Special ? FALSE : CreateDirectory(Name,NULL); |
| 11 | if (RetCode==0 && !FileExist(Name)) |
| 12 | { |
| 13 | wchar LongName[NM]; |
| 14 | if (GetWinLongPath(Name,LongName,ASIZE(LongName))) |
| 15 | RetCode=CreateDirectory(LongName,NULL); |
| 16 | } |
| 17 | if (RetCode!=0) // Non-zero return code means success for CreateDirectory. |
| 18 | { |
| 19 | if (SetAttr) |
| 20 | SetFileAttr(Name,Attr); |
| 21 | return MKDIR_SUCCESS; |
| 22 | } |
| 23 | int ErrCode=GetLastError(); |
| 24 | if (ErrCode==ERROR_FILE_NOT_FOUND || ErrCode==ERROR_PATH_NOT_FOUND) |
| 25 | return MKDIR_BADPATH; |
| 26 | return MKDIR_ERROR; |
| 27 | #elif defined(_UNIX) |
| 28 | char NameA[NM]; |
| 29 | WideToChar(Name,NameA,ASIZE(NameA)); |
| 30 | mode_t uattr=SetAttr ? (mode_t)Attr:0777; |
| 31 | int ErrCode=mkdir(NameA,uattr); |
| 32 | if (ErrCode==-1) |
| 33 | return errno==ENOENT ? MKDIR_BADPATH:MKDIR_ERROR; |
| 34 | return MKDIR_SUCCESS; |
| 35 | #else |
| 36 | return MKDIR_ERROR; |
| 37 | #endif |
| 38 | } |
| 39 | |
| 40 | |
| 41 | bool CreatePath(const wchar *Path,bool SkipLastName) |
no test coverage detected