From: Oliver Kurth Date: Wed, 10 Jun 2020 19:05:45 +0000 (-0700) Subject: Clean up lib/file/file.c X-Git-Tag: stable-11.2.0~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cbe4240689df8c7f6670bb2acf8d9c674063bb7;p=thirdparty%2Fopen-vm-tools.git Clean up lib/file/file.c Consistency with the remainder of lib/file. --- diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index 30d491959..c8cfe0211 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -1299,7 +1299,7 @@ File_Move(const char *oldFile, // IN: } } - if (asRename) { + if (asRename != NULL) { *asRename = duringRename; } @@ -1330,7 +1330,9 @@ File_Move(const char *oldFile, // IN: * * Side effects: * - Deletes the originating directory - * - In the event of a failed copy we'll leave the new directory in a state + * - In the event of a failed copy we'll leave the new directory in an + * undefined state. Calling File_DeleteDirectoryContent would be a + * good idea. * *----------------------------------------------------------------------------- */ @@ -1347,7 +1349,7 @@ File_MoveTree(const char *srcName, // IN: ASSERT(srcName != NULL); ASSERT(dstName != NULL); - if (asMove) { + if (asMove != NULL) { *asMove = FALSE; } @@ -1360,7 +1362,7 @@ File_MoveTree(const char *srcName, // IN: } if (File_Rename(srcName, dstName) == 0) { - if (asMove) { + if (asMove != NULL) { *asMove = TRUE; } @@ -1403,15 +1405,14 @@ File_MoveTree(const char *srcName, // IN: */ if (createdDir) { /* - * Check for free space on destination filesystem. - * We only check for free space if the destination directory - * did not exist. In this case, we will not be overwriting any existing - * paths, so we need as much space as srcName. + * Check for free space on destination filesystem. We only check for + * free space if the destination directory did not exist. In this + * case, we will not be overwriting any existing paths, so we need as + * much space as srcName. */ - int64 srcSize; - int64 freeSpace; - srcSize = File_GetSizeEx(srcName); - freeSpace = File_GetFreeSpace(dstName, TRUE); + int64 srcSize = File_GetSizeEx(srcName); + int64 freeSpace = File_GetFreeSpace(dstName, TRUE); + if (freeSpace < srcSize) { char *spaceStr = Msg_FormatSizeInBytes(srcSize); Msg_Append(MSGID(File.MoveTree.dst.insufficientSpace) @@ -1476,9 +1477,7 @@ File_MoveTree(const char *srcName, // IN: char * File_GetModTimeString(const char *pathName) // IN: { - int64 modTime; - - modTime = File_GetModTime(pathName); + int64 modTime = File_GetModTime(pathName); return (modTime == -1) ? NULL : TimeUtil_GetTimeFormat(modTime, TRUE, TRUE); } @@ -1655,7 +1654,7 @@ FileFirstSlashIndex(const char *pathName, // IN: UnicodeIndex firstBS; #endif - ASSERT(pathName); + ASSERT(pathName != NULL); firstFS = Unicode_FindSubstrInRange(pathName, startIndex, -1, "/", 0, 1); @@ -1836,11 +1835,10 @@ Bool File_CreateDirectoryHierarchy(const char *pathName, // IN: char **topmostCreated) // OUT/OPT: { - return File_CreateDirectoryHierarchyEx(pathName, - 0777, - topmostCreated); + return File_CreateDirectoryHierarchyEx(pathName, 0777, topmostCreated); } + /* *---------------------------------------------------------------------- * @@ -2107,7 +2105,7 @@ File_FindFileInSearchPath(const char *fileIn, // IN: sp = Util_SafeStrdup(searchPath); tok = strtok_r(sp, FILE_SEARCHPATHTOKEN, &saveptr); - while (tok) { + while (tok != NULL) { if (File_IsFullPath(tok)) { /* Fully Qualified Path. Use it. */ cur = Str_SafeAsprintf(NULL, "%s%s%s", tok, DIRSEPS, file); @@ -2137,7 +2135,7 @@ File_FindFileInSearchPath(const char *fileIn, // IN: } done: - if (cur) { + if (cur != NULL) { found = TRUE; if (result) { @@ -2715,11 +2713,12 @@ File_IsSubPathOf(const char *base, // IN: the base path to test against. char *fullPath = File_FullPath(path); Bool isSubPath = TRUE; - ASSERT(fullBase); - ASSERT(fullPath); - if ( fullPath == NULL - || fullBase == NULL - || strncmp(fullPath, fullBase, strlen(fullBase)) != 0) { + ASSERT(fullBase != NULL); + ASSERT(fullPath != NULL); + + if (fullPath == NULL || + fullBase == NULL || + strncmp(fullPath, fullBase, strlen(fullBase)) != 0) { isSubPath = FALSE; }