ICU-3933 Remove typedef for stat. Allow for single file option when calling file modification time comparison function.
X-SVN-Rev: 25233
This commit is contained in:
parent
5098438b92
commit
6466c6e250
@ -610,7 +610,7 @@ static int32_t pkg_executeOptions(UPKGOptions *o) {
|
||||
/* Check to see if a previous built data library file exists and check if it is the latest. */
|
||||
sprintf(checkLibFile, "%s%s", targetDir, libFileNames[LIB_FILE_VERSION_TMP]);
|
||||
if (T_FileStream_file_exists(checkLibFile)) {
|
||||
if (isFileModTimeLater(checkLibFile, o->srcDir)) {
|
||||
if (isFileModTimeLater(checkLibFile, o->srcDir, TRUE) && isFileModTimeLater(checkLibFile, o->options)) {
|
||||
if (o->install != NULL) {
|
||||
uprv_strcpy(libFileNames[LIB_FILE_VERSION], libFileNames[LIB_FILE_VERSION_TMP]);
|
||||
result = pkg_installLibrary(o->install, targetDir);
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "filestat.h"
|
||||
#include "filestrm.h"
|
||||
#include "cstring.h"
|
||||
#include "unicode/putil.h"
|
||||
|
||||
@ -24,64 +25,75 @@ typedef struct dirent DIRENT;
|
||||
#define SKIP2 ".."
|
||||
#endif
|
||||
|
||||
typedef struct stat STAT;
|
||||
|
||||
static int32_t whichFileModTimeIsLater(const char *file1, const char *file2);
|
||||
|
||||
/*
|
||||
* Goes through the given directory recursive to compare each file's modification time with that of the file given.
|
||||
* Also can be given just one file to check against. Default value for isDir is FALSE.
|
||||
*/
|
||||
U_CAPI UBool U_EXPORT2
|
||||
isFileModTimeLater(const char *filePath, const char *dirToCheckAgainst) {
|
||||
isFileModTimeLater(const char *filePath, const char *checkAgainst, UBool isDir) {
|
||||
UBool isLatest = TRUE;
|
||||
|
||||
if (filePath == NULL || dirToCheckAgainst == NULL) {
|
||||
if (filePath == NULL || checkAgainst == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (isDir == TRUE) {
|
||||
#if U_HAVE_DIRENT_H
|
||||
DIR *pDir = NULL;
|
||||
if ((pDir= opendir(dirToCheckAgainst)) != NULL) {
|
||||
DIR *subDirp = NULL;
|
||||
DIRENT *dirEntry = NULL;
|
||||
DIR *pDir = NULL;
|
||||
if ((pDir= opendir(checkAgainst)) != NULL) {
|
||||
DIR *subDirp = NULL;
|
||||
DIRENT *dirEntry = NULL;
|
||||
|
||||
while ((dirEntry = readdir(pDir)) != NULL) {
|
||||
if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dirEntry->d_name, SKIP2) != 0) {
|
||||
char newpath[MAX_PATH_SIZE] = "";
|
||||
uprv_strcpy(newpath, dirToCheckAgainst);
|
||||
uprv_strcat(newpath, U_FILE_SEP_STRING);
|
||||
uprv_strcat(newpath, dirEntry->d_name);
|
||||
while ((dirEntry = readdir(pDir)) != NULL) {
|
||||
if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dirEntry->d_name, SKIP2) != 0) {
|
||||
char newpath[MAX_PATH_SIZE] = "";
|
||||
uprv_strcpy(newpath, checkAgainst);
|
||||
uprv_strcat(newpath, U_FILE_SEP_STRING);
|
||||
uprv_strcat(newpath, dirEntry->d_name);
|
||||
|
||||
if ((subDirp = opendir(newpath)) != NULL) {
|
||||
/* If this new path is a directory, make a recursive call with the newpath. */
|
||||
closedir(subDirp);
|
||||
isLatest = isFileModTimeLater(filePath, newpath);
|
||||
if (!isLatest) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int32_t latest = whichFileModTimeIsLater(filePath, newpath);
|
||||
if (latest < 0 || latest == 2) {
|
||||
isLatest = FALSE;
|
||||
break;
|
||||
if ((subDirp = opendir(newpath)) != NULL) {
|
||||
/* If this new path is a directory, make a recursive call with the newpath. */
|
||||
closedir(subDirp);
|
||||
isLatest = isFileModTimeLater(filePath, newpath, isDir);
|
||||
if (!isLatest) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int32_t latest = whichFileModTimeIsLater(filePath, newpath);
|
||||
if (latest < 0 || latest == 2) {
|
||||
isLatest = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
closedir(pDir);
|
||||
} else {
|
||||
fprintf(stderr, "Unable to open directory: %s\n", checkAgainst);
|
||||
return FALSE;
|
||||
}
|
||||
closedir(pDir);
|
||||
} else {
|
||||
fprintf(stderr, "Unable to open directory: %s\n", dirToCheckAgainst);
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
if (T_FileStream_file_exists(checkAgainst)) {
|
||||
int32_t latest = whichFileModTimeIsLater(filePath, checkAgainst);
|
||||
if (latest < 0 || latest == 2) {
|
||||
isLatest = FALSE;
|
||||
}
|
||||
} else {
|
||||
isLatest = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return isLatest;
|
||||
}
|
||||
|
||||
/* Compares the mod time of both files returning a number indicating which one is later. -1 if error ocurs. */
|
||||
static int32_t whichFileModTimeIsLater(const char *file1, const char *file2) {
|
||||
int32_t result = 0;
|
||||
STAT stbuf1, stbuf2;
|
||||
struct stat stbuf1, stbuf2;
|
||||
|
||||
if (stat(file1, &stbuf1) == 0 && stat(file2, &stbuf2) == 0) {
|
||||
time_t modtime1, modtime2;
|
||||
|
@ -25,6 +25,6 @@
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
U_CAPI UBool U_EXPORT2
|
||||
isFileModTimeLater(const char *filePath, const char *dirToCheckAgainst);
|
||||
isFileModTimeLater(const char *filePath, const char *checkAgainst, UBool isDir=FALSE);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user