| OLD | NEW |
| 1 /****************************************************************************** | 1 /****************************************************************************** |
| 2 * Copyright (C) 2009-2013, International Business Machines | 2 * Copyright (C) 2009-2013, International Business Machines |
| 3 * Corporation and others. All Rights Reserved. | 3 * Corporation and others. All Rights Reserved. |
| 4 ******************************************************************************* | 4 ******************************************************************************* |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "unicode/platform.h" |
| 7 #if U_PLATFORM == U_PF_MINGW | 8 #if U_PLATFORM == U_PF_MINGW |
| 8 // *cough* - for struct stat | 9 // *cough* - for struct stat |
| 9 #ifdef __STRICT_ANSI__ | 10 #ifdef __STRICT_ANSI__ |
| 10 #undef __STRICT_ANSI__ | 11 #undef __STRICT_ANSI__ |
| 11 #endif | 12 #endif |
| 12 #endif | 13 #endif |
| 13 | 14 |
| 14 #include "filetools.h" | 15 #include "filetools.h" |
| 15 #include "filestrm.h" | 16 #include "filestrm.h" |
| 17 #include "charstr.h" |
| 16 #include "cstring.h" | 18 #include "cstring.h" |
| 17 #include "unicode/putil.h" | 19 #include "unicode/putil.h" |
| 18 #include "putilimp.h" | 20 #include "putilimp.h" |
| 19 | 21 |
| 20 #include <stdio.h> | 22 #include <stdio.h> |
| 21 #include <stdlib.h> | 23 #include <stdlib.h> |
| 22 #include <sys/stat.h> | 24 #include <sys/stat.h> |
| 23 #include <time.h> | 25 #include <time.h> |
| 24 #include <string.h> | 26 #include <string.h> |
| 25 | 27 |
| 26 #if U_HAVE_DIRENT_H | 28 #if U_HAVE_DIRENT_H |
| 27 #include <dirent.h> | 29 #include <dirent.h> |
| 28 typedef struct dirent DIRENT; | 30 typedef struct dirent DIRENT; |
| 29 | 31 |
| 30 #define MAX_PATH_SIZE 4096 /* Set the limit for the size of the path. */ | |
| 31 | |
| 32 #define SKIP1 "." | 32 #define SKIP1 "." |
| 33 #define SKIP2 ".." | 33 #define SKIP2 ".." |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 static int32_t whichFileModTimeIsLater(const char *file1, const char *file2); | 36 static int32_t whichFileModTimeIsLater(const char *file1, const char *file2); |
| 37 | 37 |
| 38 /* | 38 /* |
| 39 * Goes through the given directory recursive to compare each file's modificatio
n time with that of the file given. | 39 * Goes through the given directory recursive to compare each file's modificatio
n time with that of the file given. |
| 40 * Also can be given just one file to check against. Default value for isDir is
FALSE. | 40 * Also can be given just one file to check against. Default value for isDir is
FALSE. |
| 41 */ | 41 */ |
| 42 U_CAPI UBool U_EXPORT2 | 42 U_CAPI UBool U_EXPORT2 |
| 43 isFileModTimeLater(const char *filePath, const char *checkAgainst, UBool isDir)
{ | 43 isFileModTimeLater(const char *filePath, const char *checkAgainst, UBool isDir)
{ |
| 44 UBool isLatest = TRUE; | 44 UBool isLatest = TRUE; |
| 45 | 45 |
| 46 if (filePath == NULL || checkAgainst == NULL) { | 46 if (filePath == NULL || checkAgainst == NULL) { |
| 47 return FALSE; | 47 return FALSE; |
| 48 } | 48 } |
| 49 | 49 |
| 50 if (isDir == TRUE) { | 50 if (isDir == TRUE) { |
| 51 #if U_HAVE_DIRENT_H | 51 #if U_HAVE_DIRENT_H |
| 52 DIR *pDir = NULL; | 52 DIR *pDir = NULL; |
| 53 if ((pDir= opendir(checkAgainst)) != NULL) { | 53 if ((pDir= opendir(checkAgainst)) != NULL) { |
| 54 DIR *subDirp = NULL; | 54 DIR *subDirp = NULL; |
| 55 DIRENT *dirEntry = NULL; | 55 DIRENT *dirEntry = NULL; |
| 56 | 56 |
| 57 while ((dirEntry = readdir(pDir)) != NULL) { | 57 while ((dirEntry = readdir(pDir)) != NULL) { |
| 58 if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dir
Entry->d_name, SKIP2) != 0) { | 58 if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dir
Entry->d_name, SKIP2) != 0) { |
| 59 char newpath[MAX_PATH_SIZE] = ""; | 59 UErrorCode status = U_ZERO_ERROR; |
| 60 uprv_strcpy(newpath, checkAgainst); | 60 icu::CharString newpath(checkAgainst, -1, status); |
| 61 uprv_strcat(newpath, U_FILE_SEP_STRING); | 61 newpath.append(U_FILE_SEP_STRING, -1, status); |
| 62 uprv_strcat(newpath, dirEntry->d_name); | 62 newpath.append(dirEntry->d_name, -1, status); |
| 63 if (U_FAILURE(status)) { |
| 64 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, u_err
orName(status)); |
| 65 return FALSE; |
| 66 }; |
| 63 | 67 |
| 64 if ((subDirp = opendir(newpath)) != NULL) { | 68 if ((subDirp = opendir(newpath.data())) != NULL) { |
| 65 /* If this new path is a directory, make a recursive cal
l with the newpath. */ | 69 /* If this new path is a directory, make a recursive cal
l with the newpath. */ |
| 66 closedir(subDirp); | 70 closedir(subDirp); |
| 67 isLatest = isFileModTimeLater(filePath, newpath, isDir); | 71 isLatest = isFileModTimeLater(filePath, newpath.data(),
isDir); |
| 68 if (!isLatest) { | 72 if (!isLatest) { |
| 69 break; | 73 break; |
| 70 } | 74 } |
| 71 } else { | 75 } else { |
| 72 int32_t latest = whichFileModTimeIsLater(filePath, newpa
th); | 76 int32_t latest = whichFileModTimeIsLater(filePath, newpa
th.data()); |
| 73 if (latest < 0 || latest == 2) { | 77 if (latest < 0 || latest == 2) { |
| 74 isLatest = FALSE; | 78 isLatest = FALSE; |
| 75 break; | 79 break; |
| 76 } | 80 } |
| 77 } | 81 } |
| 78 | 82 |
| 79 } | 83 } |
| 80 } | 84 } |
| 81 closedir(pDir); | 85 closedir(pDir); |
| 82 } else { | 86 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return result; | 129 return result; |
| 126 } | 130 } |
| 127 | 131 |
| 128 /* Swap the file separater character given with the new one in the file path. */ | 132 /* Swap the file separater character given with the new one in the file path. */ |
| 129 U_CAPI void U_EXPORT2 | 133 U_CAPI void U_EXPORT2 |
| 130 swapFileSepChar(char *filePath, const char oldFileSepChar, const char newFileSep
Char) { | 134 swapFileSepChar(char *filePath, const char oldFileSepChar, const char newFileSep
Char) { |
| 131 for (int32_t i = 0, length = uprv_strlen(filePath); i < length; i++) { | 135 for (int32_t i = 0, length = uprv_strlen(filePath); i < length; i++) { |
| 132 filePath[i] = (filePath[i] == oldFileSepChar ) ? newFileSepChar : filePa
th[i]; | 136 filePath[i] = (filePath[i] == oldFileSepChar ) ? newFileSepChar : filePa
th[i]; |
| 133 } | 137 } |
| 134 } | 138 } |
| OLD | NEW |