MCPcopy Create free account
hub / github.com/MailCore/mailcore2 / addFile

Function addFile

src/core/zip/MCZip.cpp:50–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50static ErrorCode addFile(zipFile file, String * path)
51{
52 const char * cPath = path->fileSystemRepresentation();
53 struct stat statinfo;
54 int r;
55 int err;
56
57 r = stat(cPath, &statinfo);
58 if (r < 0)
59 return ErrorFile;
60
61 if (S_ISDIR(statinfo.st_mode)) {
62#ifndef _MSC_VER
63 DIR * dir = opendir(cPath);
64 if (dir == NULL) {
65 return ErrorFile;
66 }
67
68 struct dirent * ent;
69 while ((ent = readdir(dir)) != NULL) {
70 if ((strcmp(ent->d_name, ".") == 0) || (strcmp(ent->d_name, "..") == 0)) {
71 continue;
72 }
73
74 String * subpath = path->stringByAppendingPathComponent(String::stringWithFileSystemRepresentation(ent->d_name));
75 addFile(file, subpath);
76 }
77 closedir(dir);
78#else
79 String * wildcard = path->stringByAppendingPathComponent(MCSTR("*"));
80
81 HANDLE hFind = INVALID_HANDLE_VALUE;
82 WIN32_FIND_DATA ffd;
83
84 hFind = FindFirstFile(wildcard->unicodeCharacters(), &ffd);
85 if (hFind == INVALID_HANDLE_VALUE) {
86 return ErrorFile;
87 }
88
89 do {
90 if ((wcscmp(ffd.cFileName, L".") == 0) || (wcscmp(ffd.cFileName, L"..") == 0)) {
91 continue;
92 }
93 String * subpath = path->stringByAppendingPathComponent(String::stringWithCharacters(ffd.cFileName));
94 addFile(file, subpath);
95 }
96 while (FindNextFile(hFind, &ffd) != 0);
97
98 if (GetLastError() != ERROR_NO_MORE_FILES) {
99 FindClose(hFind);
100 return ErrorFile;
101 }
102
103 FindClose(hFind);
104#endif
105
106 return ErrorNone;
107 }

Callers 1

Calls 8

zipOpenNewFileInZip3Function · 0.85
zipWriteInFileInZipFunction · 0.85
zipCloseFileInZipFunction · 0.85
unicodeCharactersMethod · 0.80
lastPathComponentMethod · 0.80
statClass · 0.70

Tested by

no test coverage detected