From: Oliver Kurth Date: Fri, 2 Nov 2018 22:28:20 +0000 (-0700) Subject: Common source file changes not directly applicable to open-vm-tools. X-Git-Tag: stable-11.0.0~338 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9e178eaf036b09d12263db2118c4171b154cb69;p=thirdparty%2Fopen-vm-tools.git Common source file changes not directly applicable to open-vm-tools. On Windows, the CDR tmp files under folder "VMwareDnD" will be kept permanently in some cases after drag & drop. Root cause: The existing strategy is to delete the folder before next reboot of the machine, which is implemented through writing Windows HKLM registry. However, for the non-administrator user, that user has no permission to write the registry which in turn results in the temp files not being removed. Solution: The temp files will be removed when the user disconnect the remote desktop/app. The details are: 1. Client will remove the temp folder when remote desktop/app is disconnected (rmks exits). Server will remove the temp folder when mksvchServer plugin gets "Not Ready" notification which means mksvchanServer is disconnected from the mksvchanClient. 2. Use prefix "Horizon_xxxx(pid)-" to distinguish if the temp folder is being used by DnD or not. For Client, the pid is the rmks process id, for Server, the pid is Clipboard pid. --- diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dnd.h b/open-vm-tools/services/plugins/dndcp/dnd/dnd.h index 90f108c6b..4b8d4856e 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dnd.h +++ b/open-vm-tools/services/plugins/dndcp/dnd/dnd.h @@ -273,7 +273,9 @@ Bool DnD_UriIsNonFileSchemes(char const *uri); */ const char *DnD_GetFileRoot(void); char *DnD_CreateStagingDirectory(void); +char *DnD_AppendPrefixToStagingDir(const char *oldName, const char *newName); Bool DnD_DeleteStagingFiles(const char *stagingDir, Bool onReboot); +Bool DnD_RemoveTempDirs(const char *dndTempDir, const char *prefix); int DnD_LegacyConvertToCPName(const char *nameIn, size_t bufOutSize, char *bufOut); diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c b/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c index 973d29519..d9d9d22fb 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2005-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2005-2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -164,6 +164,44 @@ exit: #endif // ifndef DND_IS_XDG +/* + *----------------------------------------------------------------------------- + * + * DnD_AppendPrefixToStagingDir -- + * + * Append prefix to a DnD staging directory + * + * Results: + * Return new DnD staging directory for success, NULL otherwise. + * + * Side effects: + * Caller must free the retrun string with free + * + *----------------------------------------------------------------------------- + */ +char * +DnD_AppendPrefixToStagingDir(const char *stagingDir, // IN: + const char *prefix) // IN: +{ + const char *dndRoot = NULL; + char *newDir = NULL; + + dndRoot = DnD_GetFileRoot(); + if (Unicode_Find(stagingDir, dndRoot) == UNICODE_INDEX_NOT_FOUND) { + // incorrect staging directory + Log("%s: Not find root = %s\n", __FUNCTION__, dndRoot); + return NULL; + } + + newDir = Unicode_Insert(stagingDir, Unicode_LengthInCodePoints(dndRoot), prefix); + if (0 != File_Rename(stagingDir, newDir)) { + free(newDir); + newDir = NULL; + } + return newDir; +} + + /* *----------------------------------------------------------------------------- * @@ -213,6 +251,8 @@ DnD_DeleteStagingFiles(const char *stagingDir, // IN: if (numFiles == -1) { return FALSE; + } else if (numFiles == 0) { + return TRUE; } /* delete everything in the directory */ @@ -237,8 +277,71 @@ DnD_DeleteStagingFiles(const char *stagingDir, // IN: } free(base); + Util_FreeStringList(fileList, numFiles); + } + + return ret; +} + + +/* + *----------------------------------------------------------------------------- + * + * DnD_RemoveTempDirs -- + * + * Remove all directories with the specific prefix in the staging directory. + * + * Results: + * TRUE if the specific directories were deleted. FALSE if there was an error. + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +Bool +DnD_RemoveTempDirs(const char *dndTempDir, // IN: + const char *prefix) // IN: +{ + Bool ret = TRUE; + int i = 0; + int numFiles = 0; + char *base = NULL; + char **fileList = NULL; + + ASSERT(dndTempDir); + + if (!File_Exists(dndTempDir)) { + /* The dndTempDir doesn't exist. */ + return TRUE; + } + + if (!File_IsDirectory(dndTempDir)) { + return FALSE; } + /* get list of files in current directory */ + numFiles = File_ListDirectory(dndTempDir, &fileList); + if (numFiles == -1) { + return FALSE; + } else if (numFiles == 0) { + return TRUE; + } + + base = Unicode_Append(dndTempDir, DIRSEPS); + for (i = 0; i < numFiles; i++) { + char *curPath = Unicode_Append(base, fileList[i]); + if (File_IsDirectory(curPath) && + (UNICODE_INDEX_NOT_FOUND != Unicode_Find(curPath, prefix))) { + if (!File_DeleteDirectoryTree(curPath)) { + ret = FALSE; + } + } + free(curPath); + } + free(base); + Util_FreeStringList(fileList, numFiles); return ret; }