]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Common source file changes not directly applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Fri, 2 Nov 2018 22:28:21 +0000 (15:28 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 2 Nov 2018 22:28:21 +0000 (15:28 -0700)
Re-apply the DnD changes previously backed out.

On Windows, the CDR tmp files under folder "VMwareDnD" will be kept
permanently in some cases after drag & drop.i

open-vm-tools/services/plugins/dndcp/dnd/dnd.h
open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c

index 90f108c6ba5425fe78e9a7282a95a0fa9d3a5f38..4b8d4856e2fbd4e1b1c94dc178527a8aebafa34e 100644 (file)
@@ -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);
index 973d2951990cb999b1c11ec77e24fa1bc1449f99..d9d9d22fb09de24b88ffe69e6e3e381805e104aa 100644 (file)
@@ -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;
 }