osDir.c 11.1 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

L
Liu Jicong 已提交
16
#define _DEFAULT_SOURCE
wafwerar's avatar
wafwerar 已提交
17
#define ALLOW_FORBID_FUNC
L
Liu Jicong 已提交
18

S
Shengliang Guan 已提交
19
#include "os.h"
S
TD-1574  
Shengliang Guan 已提交
20

wafwerar's avatar
wafwerar 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33
#ifdef WINDOWS

#include <windows.h>

typedef struct TdDirEntry {
  WIN32_FIND_DATA findFileData;
} TdDirEntry;

typedef struct TdDir {
  TdDirEntry dirEntry;
  HANDLE     hFind;
} TdDir;

wafwerar's avatar
wafwerar 已提交
34 35 36 37 38 39 40 41 42
enum
  {
    WRDE_NOSPACE = 1,		/* Ran out of memory.  */
    WRDE_BADCHAR,		/* A metachar appears in the wrong place.  */
    WRDE_BADVAL,		/* Undefined var reference with WRDE_UNDEF.  */
    WRDE_CMDSUB,		/* Command substitution with WRDE_NOCMD.  */
    WRDE_SYNTAX			/* Shell syntax error.  */
  };

wafwerar's avatar
wafwerar 已提交
43 44 45 46 47 48 49 50
int wordexp(char *words, wordexp_t *pwordexp, int flags) {
  pwordexp->we_offs = 0;
  pwordexp->we_wordc = 1;
  pwordexp->we_wordv[0] = pwordexp->wordPos;

  memset(pwordexp->wordPos, 0, 1025);
  if (_fullpath(pwordexp->wordPos, words, 1024) == NULL) {
    pwordexp->we_wordv[0] = words;
wafwerar's avatar
wafwerar 已提交
51
    printf("failed to parse relative path:%s to abs path\n", words);
wafwerar's avatar
wafwerar 已提交
52 53 54
    return -1;
  }

wafwerar's avatar
wafwerar 已提交
55
  // printf("parse relative path:%s to abs path:%s\n", words, pwordexp->wordPos);
wafwerar's avatar
wafwerar 已提交
56 57
  return 0;
}
S
Shengliang Guan 已提交
58

wafwerar's avatar
wafwerar 已提交
59
void wordfree(wordexp_t *pwordexp) {}
S
Shengliang Guan 已提交
60

wafwerar's avatar
wafwerar 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#elif defined(DARWIN)

#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wordexp.h>

typedef struct dirent dirent;
typedef struct dirent TdDirEntry;

typedef struct TdDir {
  TdDirEntry    dirEntry;
  TdDirEntry    dirEntry1;
  TdDirEntryPtr dirEntryPtr;
  DIR          *pDir;
} TdDir;

S
Shengliang Guan 已提交
79
#else
S
Shengliang Guan 已提交
80

S
Shengliang Guan 已提交
81 82 83 84 85 86
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wordexp.h>

wafwerar's avatar
wafwerar 已提交
87
typedef struct dirent dirent;
dengyihao's avatar
dengyihao 已提交
88
typedef struct DIR    TdDir;
wafwerar's avatar
wafwerar 已提交
89 90 91
typedef struct dirent TdDirEntry;

#endif
wafwerar's avatar
wafwerar 已提交
92

H
Hongze Cheng 已提交
93
void taosRemoveDir(const char *dirname) {
wafwerar's avatar
wafwerar 已提交
94 95
  TdDirPtr pDir = taosOpenDir(dirname);
  if (pDir == NULL) return;
S
Shengliang Guan 已提交
96

wafwerar's avatar
wafwerar 已提交
97 98 99
  TdDirEntryPtr de = NULL;
  while ((de = taosReadDir(pDir)) != NULL) {
    if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue;
S
TD-4088  
Shengliang Guan 已提交
100

S
Shengliang Guan 已提交
101 102
    char filename[1024] = {0};
    snprintf(filename, sizeof(filename), "%s%s%s", dirname, TD_DIRSEP, taosGetDirEntryName(de));
wafwerar's avatar
wafwerar 已提交
103
    if (taosDirEntryIsDir(de)) {
S
Shengliang Guan 已提交
104 105
      taosRemoveDir(filename);
    } else {
106
      (void)taosRemoveFile(filename);
dengyihao's avatar
dengyihao 已提交
107
      // printf("file:%s is removed\n", filename);
S
Shengliang Guan 已提交
108 109 110
    }
  }

wafwerar's avatar
wafwerar 已提交
111
  taosCloseDir(&pDir);
S
Shengliang Guan 已提交
112
  rmdir(dirname);
S
Shengliang Guan 已提交
113

dengyihao's avatar
dengyihao 已提交
114
  // printf("dir:%s is removed\n", dirname);
wafwerar's avatar
wafwerar 已提交
115
  return;
S
Shengliang Guan 已提交
116 117
}

wafwerar's avatar
wafwerar 已提交
118
bool taosDirExist(const char *dirname) { return taosCheckExistFile(dirname); }
119

120
int32_t taosMkDir(const char *dirname) {
wafwerar's avatar
wafwerar 已提交
121 122 123 124
  if (taosDirExist(dirname)) return 0;
#ifdef WINDOWS
  int32_t code = _mkdir(dirname, 0755);
#else
wafwerar's avatar
wafwerar 已提交
125
  int32_t code = mkdir(dirname, 0755);
wafwerar's avatar
wafwerar 已提交
126
#endif
wafwerar's avatar
wafwerar 已提交
127 128 129 130 131 132 133 134
  if (code < 0 && errno == EEXIST) {
    return 0;
  }

  return code;
}

int32_t taosMulMkDir(const char *dirname) {
wafwerar's avatar
wafwerar 已提交
135
  if (dirname == NULL) return -1;
L
Liu Jicong 已提交
136 137
  char    temp[1024];
  char   *pos = temp;
wafwerar's avatar
wafwerar 已提交
138
  int32_t code = 0;
wafwerar's avatar
wafwerar 已提交
139 140
#ifdef WINDOWS
  taosRealPath(dirname, temp, sizeof(temp));
wafwerar's avatar
wafwerar 已提交
141
  if (temp[1] == ':') pos += 3;
wafwerar's avatar
wafwerar 已提交
142 143 144
#else
  strcpy(temp, dirname);
#endif
wafwerar's avatar
wafwerar 已提交
145

wafwerar's avatar
wafwerar 已提交
146 147 148
  if (taosDirExist(temp)) return code;

  if (strncmp(temp, TD_DIRSEP, 1) == 0) {
wafwerar's avatar
wafwerar 已提交
149
    pos += 1;
wafwerar's avatar
wafwerar 已提交
150
  } else if (strncmp(temp, "." TD_DIRSEP, 2) == 0) {
wafwerar's avatar
wafwerar 已提交
151 152
    pos += 2;
  }
dengyihao's avatar
dengyihao 已提交
153 154

  for (; *pos != '\0'; pos++) {
wafwerar's avatar
wafwerar 已提交
155
    if (*pos == TD_DIRSEP[0]) {
wafwerar's avatar
wafwerar 已提交
156
      *pos = '\0';
L
Liu Jicong 已提交
157
#ifdef WINDOWS
wafwerar's avatar
wafwerar 已提交
158
      code = _mkdir(temp, 0755);
L
Liu Jicong 已提交
159
#else
wafwerar's avatar
wafwerar 已提交
160
      code = mkdir(temp, 0755);
L
Liu Jicong 已提交
161
#endif
wafwerar's avatar
wafwerar 已提交
162
      if (code < 0 && errno != EEXIST) {
wafwerar's avatar
wafwerar 已提交
163
        terrno = TAOS_SYSTEM_ERROR(errno);
wafwerar's avatar
wafwerar 已提交
164 165
        return code;
      }
wafwerar's avatar
wafwerar 已提交
166
      *pos = TD_DIRSEP[0];
wafwerar's avatar
wafwerar 已提交
167 168
    }
  }
dengyihao's avatar
dengyihao 已提交
169

wafwerar's avatar
wafwerar 已提交
170
  if (*(pos - 1) != TD_DIRSEP[0]) {
L
Liu Jicong 已提交
171
#ifdef WINDOWS
wafwerar's avatar
wafwerar 已提交
172
    code = _mkdir(temp, 0755);
L
Liu Jicong 已提交
173
#else
wafwerar's avatar
wafwerar 已提交
174
    code = mkdir(temp, 0755);
L
Liu Jicong 已提交
175
#endif
wafwerar's avatar
wafwerar 已提交
176
    if (code < 0 && errno != EEXIST) {
wafwerar's avatar
wafwerar 已提交
177
      terrno = TAOS_SYSTEM_ERROR(errno);
wafwerar's avatar
wafwerar 已提交
178 179 180 181 182
      return code;
    }
  }

  // int32_t code = mkdir(dirname, 0755);
S
Shengliang Guan 已提交
183
  if (code < 0 && errno == EEXIST) {
184
    return 0;
S
Shengliang Guan 已提交
185 186
  }

187
  return code;
S
Shengliang Guan 已提交
188 189
}

wafwerar's avatar
wafwerar 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
int32_t taosMulModeMkDir(const char *dirname, int mode) {
  if (dirname == NULL) return -1;
  char    temp[1024];
  char   *pos = temp;
  int32_t code = 0;
#ifdef WINDOWS
  taosRealPath(dirname, temp, sizeof(temp));
  if (temp[1] == ':') pos += 3;
#else
  strcpy(temp, dirname);
#endif

  if (taosDirExist(temp)) {
    chmod(temp, mode);
    return code;
  }

  if (strncmp(temp, TD_DIRSEP, 1) == 0) {
    pos += 1;
  } else if (strncmp(temp, "." TD_DIRSEP, 2) == 0) {
    pos += 2;
  }

  for (; *pos != '\0'; pos++) {
    if (*pos == TD_DIRSEP[0]) {
      *pos = '\0';
#ifdef WINDOWS
      code = _mkdir(temp, mode);
#else
      code = mkdir(temp, mode);
#endif
      if (code < 0 && errno != EEXIST) {
        terrno = TAOS_SYSTEM_ERROR(errno);
        return code;
      }
      *pos = TD_DIRSEP[0];
    }
  }

  if (*(pos - 1) != TD_DIRSEP[0]) {
#ifdef WINDOWS
    code = _mkdir(temp, mode);
#else
    code = mkdir(temp, mode);
#endif
    if (code < 0 && errno != EEXIST) {
      terrno = TAOS_SYSTEM_ERROR(errno);
      return code;
    }
  }

  if (code < 0 && errno == EEXIST) {
    chmod(temp, mode);
    return 0;
  }

  chmod(temp, mode);
  return code;
}

S
config  
Shengliang Guan 已提交
250
void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
wafwerar's avatar
wafwerar 已提交
251 252
  TdDirPtr pDir = taosOpenDir(dirname);
  if (pDir == NULL) return;
S
TD-1263  
Shengliang Guan 已提交
253

dengyihao's avatar
dengyihao 已提交
254
  int64_t       sec = taosGetTimestampSec();
wafwerar's avatar
wafwerar 已提交
255
  TdDirEntryPtr de = NULL;
S
TD-1263  
Shengliang Guan 已提交
256

wafwerar's avatar
wafwerar 已提交
257 258
  while ((de = taosReadDir(pDir)) != NULL) {
    if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue;
S
TD-1263  
Shengliang Guan 已提交
259 260

    char filename[1024];
wafwerar's avatar
wafwerar 已提交
261 262
    snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de));
    if (taosDirEntryIsDir(de)) {
S
TD-1263  
Shengliang Guan 已提交
263 264
      continue;
    } else {
S
Shengliang Guan 已提交
265
      int32_t len = (int32_t)strlen(filename);
S
TD-1574  
Shengliang Guan 已提交
266 267 268 269
      if (len > 3 && strcmp(filename + len - 3, ".gz") == 0) {
        len -= 3;
      }

S
TD-1263  
Shengliang Guan 已提交
270
      int64_t fileSec = 0;
S
Shengliang Guan 已提交
271
      for (int32_t i = len - 1; i >= 0; i--) {
S
TD-1263  
Shengliang Guan 已提交
272
        if (filename[i] == '.') {
S
TD-1263  
Shengliang Guan 已提交
273
          fileSec = atoll(filename + i + 1);
S
TD-1263  
Shengliang Guan 已提交
274 275 276 277
          break;
        }
      }

S
TD-1263  
Shengliang Guan 已提交
278
      if (fileSec <= 100) continue;
dengyihao's avatar
dengyihao 已提交
279
      int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1);
S
TD-1263  
Shengliang Guan 已提交
280
      if (days > keepDays) {
281
        (void)taosRemoveFile(filename);
dengyihao's avatar
dengyihao 已提交
282
        // printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
S
TD-1263  
Shengliang Guan 已提交
283
      } else {
dengyihao's avatar
dengyihao 已提交
284
        // printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
S
TD-1263  
Shengliang Guan 已提交
285 286 287 288
      }
    }
  }

wafwerar's avatar
wafwerar 已提交
289
  taosCloseDir(&pDir);
S
Shengliang Guan 已提交
290
  rmdir(dirname);
S
TD-1263  
Shengliang Guan 已提交
291
}
S
TD-1574  
Shengliang Guan 已提交
292

S
config  
Shengliang Guan 已提交
293
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
S
Shengliang Guan 已提交
294
  wordexp_t full_path;
wafwerar's avatar
wafwerar 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
  switch (wordexp (dirname, &full_path, 0)) {
  case 0:
    break;
  case WRDE_NOSPACE:
    wordfree (&full_path);
    // printf("failed to expand path:%s since Out of memory\n", dirname);
    return -1;
  case WRDE_BADCHAR:
    // printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n", dirname);
    return -1;
  case WRDE_SYNTAX:
    // printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched quotes\n", dirname);
    return -1;
  default:
    // printf("failed to expand path:%s since %s\n", dirname, strerror(errno));
310
    return -1;
S
TD-1574  
Shengliang Guan 已提交
311 312
  }

S
Shengliang Guan 已提交
313 314
  if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
    strncpy(outname, full_path.we_wordv[0], maxlen);
S
TD-1574  
Shengliang Guan 已提交
315 316
  }

S
Shengliang Guan 已提交
317
  wordfree(&full_path);
S
TD-1574  
Shengliang Guan 已提交
318

319
  return 0;
S
Shengliang Guan 已提交
320
}
S
TD-1574  
Shengliang Guan 已提交
321

wafwerar's avatar
wafwerar 已提交
322
int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
S
Shengliang Guan 已提交
323
  char tmp[PATH_MAX] = {0};
wafwerar's avatar
wafwerar 已提交
324
#ifdef WINDOWS
wafwerar's avatar
wafwerar 已提交
325
  if (_fullpath(tmp, dirname, maxlen) != NULL) {
wafwerar's avatar
wafwerar 已提交
326
#else
S
Shengliang Guan 已提交
327
  if (realpath(dirname, tmp) != NULL) {
wafwerar's avatar
wafwerar 已提交
328 329 330 331 332 333 334
#endif
    if (realPath == NULL) {
      strncpy(dirname, tmp, maxlen);
    } else {
      strncpy(realPath, tmp, maxlen);
    }
    return 0;
S
TD-1574  
Shengliang Guan 已提交
335 336
  }

wafwerar's avatar
wafwerar 已提交
337
  return -1;
S
TD-1574  
Shengliang Guan 已提交
338
}
S
Shengliang Guan 已提交
339

340
bool taosIsDir(const char *dirname) {
wafwerar's avatar
wafwerar 已提交
341 342 343
  TdDirPtr pDir = taosOpenDir(dirname);
  if (pDir != NULL) {
    taosCloseDir(&pDir);
344 345 346 347 348
    return true;
  }
  return false;
}

dengyihao's avatar
dengyihao 已提交
349
char *taosDirName(char *name) {
wafwerar's avatar
wafwerar 已提交
350
#ifdef WINDOWS
dengyihao's avatar
dengyihao 已提交
351
  char Drive1[MAX_PATH], Dir1[MAX_PATH];
wafwerar's avatar
wafwerar 已提交
352 353 354
  _splitpath(name, Drive1, Dir1, NULL, NULL);
  size_t dirNameLen = strlen(Drive1) + strlen(Dir1);
  if (dirNameLen > 0) {
wafwerar's avatar
wafwerar 已提交
355 356 357 358 359 360 361
    if (name[dirNameLen - 1] == '/' || name[dirNameLen - 1] == '\\') {
      name[dirNameLen - 1] = 0;
    } else {
      name[dirNameLen] = 0;
    }
  } else {
    name[0] = 0;
wafwerar's avatar
wafwerar 已提交
362 363
  }
  return name;
wafwerar's avatar
wafwerar 已提交
364
#else
wafwerar's avatar
wafwerar 已提交
365 366 367 368 369 370
  char *end = strrchr(name, '/');
  if (end != NULL) {
    *end = '\0';
  } else {
    name[0] = 0;
  }
L
Liu Jicong 已提交
371
  return name;
wafwerar's avatar
wafwerar 已提交
372
#endif
wafwerar's avatar
wafwerar 已提交
373 374
}

dengyihao's avatar
dengyihao 已提交
375
char *taosDirEntryBaseName(char *name) {
wafwerar's avatar
wafwerar 已提交
376 377 378 379 380
#ifdef WINDOWS
  char Filename1[MAX_PATH], Ext1[MAX_PATH];
  _splitpath(name, NULL, NULL, Filename1, Ext1);
  return name + (strlen(name) - strlen(Filename1) - strlen(Ext1));
#else
wafwerar's avatar
wafwerar 已提交
381 382 383
  char *pPoint = strchr(name, '.');
  if (pPoint != NULL) pPoint = 0;
  return name;
wafwerar's avatar
wafwerar 已提交
384
#endif
wafwerar's avatar
wafwerar 已提交
385 386 387 388 389 390
}

TdDirPtr taosOpenDir(const char *dirname) {
  if (dirname == NULL) {
    return NULL;
  }
wafwerar's avatar
wafwerar 已提交
391 392

#ifdef WINDOWS
dengyihao's avatar
dengyihao 已提交
393 394
  char   szFind[MAX_PATH];  //这是要找的
  HANDLE hFind;
wafwerar's avatar
wafwerar 已提交
395 396 397 398 399 400 401 402 403 404 405 406

  TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir));

  strcpy(szFind, dirname);
  strcat(szFind, "\\*.*");  //利用通配符找这个目录下的所以文件,包括目录

  pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
  if (INVALID_HANDLE_VALUE == pDir->hFind) {
    taosMemoryFree(pDir);
    return NULL;
  }
  return pDir;
wafwerar's avatar
wafwerar 已提交
407 408 409 410 411 412 413
#elif defined(DARWIN)
  DIR *pDir = opendir(dirname);
  if (pDir == NULL) return NULL;
  TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir));
  dirPtr->dirEntryPtr = (TdDirEntryPtr)&(dirPtr->dirEntry1);
  dirPtr->pDir = pDir;
  return dirPtr;
wafwerar's avatar
wafwerar 已提交
414
#else
wafwerar's avatar
wafwerar 已提交
415
  return (TdDirPtr)opendir(dirname);
wafwerar's avatar
wafwerar 已提交
416
#endif
wafwerar's avatar
wafwerar 已提交
417 418 419 420 421 422
}

TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
  if (pDir == NULL) {
    return NULL;
  }
wafwerar's avatar
wafwerar 已提交
423 424 425 426
#ifdef WINDOWS
  if (!FindNextFile(pDir->hFind, &(pDir->dirEntry.findFileData))) {
    return NULL;
  }
dengyihao's avatar
dengyihao 已提交
427
  return (TdDirEntryPtr) & (pDir->dirEntry.findFileData);
wafwerar's avatar
wafwerar 已提交
428 429 430 431 432 433
#elif defined(DARWIN)
  if (readdir_r(pDir->pDir, (dirent*)&(pDir->dirEntry), (dirent**)&(pDir->dirEntryPtr)) == 0) {
    return pDir->dirEntryPtr;
  } else {
    return NULL;
  }
wafwerar's avatar
wafwerar 已提交
434
#else
dengyihao's avatar
dengyihao 已提交
435
  return (TdDirEntryPtr)readdir((DIR *)pDir);
wafwerar's avatar
wafwerar 已提交
436
#endif
wafwerar's avatar
wafwerar 已提交
437 438 439 440 441 442
}

bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
  if (pDirEntry == NULL) {
    return false;
  }
wafwerar's avatar
wafwerar 已提交
443 444 445
#ifdef WINDOWS
  return (pDirEntry->findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else
dengyihao's avatar
dengyihao 已提交
446
  return (((dirent *)pDirEntry)->d_type & DT_DIR) != 0;
wafwerar's avatar
wafwerar 已提交
447
#endif
wafwerar's avatar
wafwerar 已提交
448 449
}

dengyihao's avatar
dengyihao 已提交
450
char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
L
Liu Jicong 已提交
451 452 453
  /*if (pDirEntry == NULL) {*/
  /*return NULL;*/
  /*}*/
wafwerar's avatar
wafwerar 已提交
454 455 456
#ifdef WINDOWS
  return pDirEntry->findFileData.cFileName;
#else
dengyihao's avatar
dengyihao 已提交
457
  return ((dirent *)pDirEntry)->d_name;
wafwerar's avatar
wafwerar 已提交
458
#endif
wafwerar's avatar
wafwerar 已提交
459 460
}

wafwerar's avatar
wafwerar 已提交
461 462
int32_t taosCloseDir(TdDirPtr *ppDir) {
  if (ppDir == NULL || *ppDir == NULL) {
wafwerar's avatar
wafwerar 已提交
463 464
    return -1;
  }
wafwerar's avatar
wafwerar 已提交
465 466 467 468 469
#ifdef WINDOWS
  FindClose((*ppDir)->hFind);
  taosMemoryFree(*ppDir);
  *ppDir = NULL;
  return 0;
wafwerar's avatar
wafwerar 已提交
470 471 472 473 474
#elif defined(DARWIN)
  closedir((*ppDir)->pDir);
  taosMemoryFree(*ppDir);
  *ppDir = NULL;
  return 0;
wafwerar's avatar
wafwerar 已提交
475
#else
dengyihao's avatar
dengyihao 已提交
476
  closedir((DIR *)*ppDir);
wafwerar's avatar
wafwerar 已提交
477 478
  *ppDir = NULL;
  return 0;
L
Liu Jicong 已提交
479
#endif
wafwerar's avatar
wafwerar 已提交
480
}