Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 159204 Details for
Bug 296799
IFileManagerExtended.deleteDirectory(FileIdentifierList) does not work.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch to native file server
bug-296799.patch.txt (text/plain), 14.63 KB, created by
Jonathan West
on 2010-02-16 11:13:10 EST
(
hide
)
Description:
Patch to native file server
Filename:
MIME Type:
Creator:
Jonathan West
Created:
2010-02-16 11:13:10 EST
Size:
14.63 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.tptp.platform.agentcontroller >Index: src-native-new/include/tptp/TPTPUtils.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/TPTPUtils.h,v >retrieving revision 1.29 >diff -u -r1.29 TPTPUtils.h >--- src-native-new/include/tptp/TPTPUtils.h 24 Sep 2009 21:02:06 -0000 1.29 >+++ src-native-new/include/tptp/TPTPUtils.h 8 Feb 2010 19:45:14 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2009 Intel Corporation and others. >+ * Copyright (c) 2005, 2010 Intel Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -319,6 +319,43 @@ > > int vrfusrpwd(tptp_string *userid, tptp_string *password); > >+ >+// Recursive Directory Deletion Implementation =============== >+ >+#ifdef _WIN32 >+ >+ typedef struct { >+ HANDLE hFind; >+ WIN32_FIND_DATA findData; >+ } fileDirectoryPos; >+ >+#else >+ >+ #include <sys/types.h> >+ #include <dirent.h> >+ >+ typedef struct { >+ DIR * dirPointer; >+ char * currEntry; >+ } fileDirectoryPos; >+ >+#endif >+ >+/** Returns 1 if is a directory, 0 if not, -1 if file does not exist or there is some other error*/ >+int isDirectory(char * path); >+ >+fileDirectoryPos * fileOpenDir(char *fileName); >+ >+char * getPathFromDirPos(fileDirectoryPos * dirPos); >+ >+int advanceToNextDirPos(fileDirectoryPos * dirPos); >+ >+int rmdirDirectory(char * path); >+ >+void closeDirPos(fileDirectoryPos *dirPos); >+ >+int fileExists(char * path); >+ > #ifdef __cplusplus > } /* Ends extern C */ > #endif >Index: src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp,v >retrieving revision 1.51 >diff -u -r1.51 TPTPUtil.cpp >--- src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 28 Jan 2010 20:26:53 -0000 1.51 >+++ src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 8 Feb 2010 19:45:14 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2010 Intel Corporation. >+ * Copyright (c) 2005, 2010 Intel Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -39,6 +39,7 @@ > #ifdef _WIN32 > #include <sys/types.h> > #include <sys/stat.h> >+ #include <errno.h> > #define TPTP_STAT _stat > #define mode_t unsigned short > #define S_ISDIR(mode) (((mode)&_S_IFMT) == _S_IFDIR) >@@ -2276,3 +2277,197 @@ > } > > >+/** Returns 1 if file (or directory) exists, 0 if not, -1 if there is some other error*/ >+int fileExists(char * path) { >+ #ifdef _WIN32 >+ >+ struct _stat statbuf; >+ int result = 0; >+ >+ result = _stat(path, &statbuf); >+ >+ if(result != 0) { >+ if(errno == ENOENT) { >+ return 0; >+ } else { >+ return -1; >+ } >+ >+ } >+ >+ return 1; >+ >+ #else >+ struct stat statbuf; >+ int result = 0; >+ >+ result = stat(path, &statbuf); >+ >+ if(result != 0) { >+ if(errno == ENOENT) { >+ return 0; >+ } else { >+ return -1; >+ } >+ >+ } >+ >+ return 1; >+ #endif >+} >+ >+ >+ >+/** Returns 1 if is a directory, 0 if not, -1 if file does not exist or there is some other error*/ >+int isDirectory(char * path) { >+ #ifdef _WIN32 >+ if(path == 0) return -1; >+ >+ DWORD attrs; >+ attrs = GetFileAttributes(path); >+ >+ if (attrs == INVALID_FILE_ATTRIBUTES) return -1; >+ >+ return (attrs & FILE_ATTRIBUTE_DIRECTORY) > 0; >+ >+ #else >+ >+ struct stat statbuf; >+ int result = 0; >+ >+ result = stat(path, &statbuf); >+ >+ if(result != 0) { >+ return -1; >+ } >+ >+ return S_ISDIR(statbuf.st_mode); >+ >+ #endif >+} >+ >+ >+/** Returns 0 if successful, -1 otherwise*/ >+int rmdirDirectory(char * path) { >+ int r = 0; >+ >+ #ifdef _WIN32 >+ >+ r = RemoveDirectory(path); >+ >+ // If the operation reports to have succeeded, or the directory no longer exists, then return >+ if(r != 0 || fileExists(path) == 0) { >+ return 0; >+ } else { >+ return -1; >+ } >+ >+ #else >+ >+ // Attempt to remove directory first -- this will succeed on either empty directories, or sym links >+ // Do not remove this -- this is to prevent recursion into the contents of symlinked dirs which shouldn't be deleted >+ r = remove(path); >+ if(r == 0 || fileExists(path) == 0) { >+ return 0; >+ } else { >+ return -1; >+ } >+ >+ #endif >+ >+} >+ >+fileDirectoryPos * fileOpenDir(char *fileName) { >+ fileDirectoryPos * result; >+ >+ #ifdef _WIN32 >+ char *updatedPath; >+ >+ // the FindFirstFile API requires a wildcard at the end of the path, so we append one >+ // length is = strlen(fileName) + 2 (\*) + 1 (\0) + 1 (buffer) >+ updatedPath = (char *)malloc(strlen(fileName) + 2 + 1 + 1 ); >+ sprintf(updatedPath, "%s\\*", fileName); >+ >+ result = (fileDirectoryPos *)malloc(sizeof(fileDirectoryPos)); >+ >+ result->hFind = FindFirstFile(updatedPath, &(result->findData)); >+ >+ free(updatedPath); >+ >+ if (result->hFind == INVALID_HANDLE_VALUE) { >+ free(result); >+ return 0; >+ } else { >+ return result; >+ } >+ >+ #else >+ >+ DIR *dir; >+ struct dirent *ep; >+ dir = opendir (fileName); >+ if(dir == 0) return 0; >+ >+ ep = readdir (dir); >+ if(ep == 0) return 0; >+ >+ result = (fileDirectoryPos *) malloc(sizeof(fileDirectoryPos)); >+ >+ result->dirPointer = dir; >+ result->currEntry = ep->d_name; >+ >+ return result; >+ >+ #endif >+ >+} >+ >+char * getPathFromDirPos(fileDirectoryPos * dirPos) { >+ if(dirPos == 0) return 0; >+ >+ #ifdef _WIN32 >+ return dirPos->findData.cFileName; >+ #else >+ return dirPos->currEntry; >+ #endif >+ >+} >+ >+int advanceToNextDirPos(fileDirectoryPos * dirPos) { >+ >+ #ifdef _WIN32 >+ >+ int result; >+ >+ result = FindNextFile(dirPos->hFind, &(dirPos->findData)); >+ if(result == 0) { >+ return -1; >+ } >+ >+ return 0; >+ >+ #else >+ >+ struct dirent *ep; >+ >+ ep = readdir (dirPos->dirPointer); >+ if(ep == 0) return -1; >+ >+ dirPos->currEntry = ep->d_name; >+ >+ return 0; >+ >+ #endif >+ >+} >+ >+void closeDirPos(fileDirectoryPos *dirPos) { >+ >+ #ifdef _WIN32 >+ FindClose(dirPos->hFind); >+ #else >+ closedir (dirPos->dirPointer); >+ #endif >+ >+ free(dirPos); >+} >Index: src-native-new/src/shared/TPTPUtil/TPTUtil.def >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPUtil/TPTUtil.def,v >retrieving revision 1.32 >diff -u -r1.32 TPTUtil.def >--- src-native-new/src/shared/TPTPUtil/TPTUtil.def 10 Oct 2008 21:54:48 -0000 1.32 >+++ src-native-new/src/shared/TPTPUtil/TPTUtil.def 8 Feb 2010 19:45:14 -0000 >@@ -103,4 +103,10 @@ > validateDirectory > isAbsolutePath > getTempDir >- >\ No newline at end of file >+ isDirectory >+ fileOpenDir >+ getPathFromDirPos >+ advanceToNextDirPos >+ closeDirPos >+ fileExists >+ rmdirDirectory >Index: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c,v >retrieving revision 1.9 >diff -u -r1.9 nativeFileServer.c >--- src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c 26 Aug 2009 14:59:58 -0000 1.9 >+++ src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c 8 Feb 2010 19:45:14 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008, 2009 Intel Corporation. >+ * Copyright (c) 2008, 2010 Intel Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -15,6 +15,25 @@ > #include "nativeFileServer.h" > #include "tptp/TPTPUtils.h" > >+#include <stdio.h> >+#include <stdlib.h> >+ >+#include <sys/types.h> >+#include <sys/stat.h> >+#include <errno.h> >+ >+#ifdef _WIN32 >+ #define WIN32_LEAN_AND_MEAN >+ #include <windows.h> >+#else >+ >+ #include <unistd.h> >+ #include <dirent.h> >+ >+#endif >+ >+int deleteDirectory(char * path); >+ > int readInt (SOCKET socket, int* value) { > int bytesRead, bytesToRead, i, d, r; > unsigned char* p; >@@ -396,6 +415,28 @@ > return 0; > } > >+int processDeleteDirCmd(fs_connection_block_t* con) { >+ int i, numFiles, num; >+ char* name; >+ >+ readInt(con->socket, &numFiles); >+ readInt(con->socket, &num); >+ if (num <= 0) return -1; >+ >+ for (i=0; i<num; i++) { >+ name = readStringIntoBuffer(con); >+ if (name == NULL) return -1; >+ >+ deleteDirectory(name); >+ >+ remove(name); >+ } >+ >+ return 0; >+ >+} >+ >+ > int processDeleteFileCmd(fs_connection_block_t* con) { > int i, numFiles, num; > char* name; >@@ -499,8 +540,10 @@ > return processFileArrayCmd(con, cmd); > > case DELETE_FILE_COMMAND: >- case DELETE_DIR_COMMAND: > return processDeleteFileCmd(con); >+ >+ case DELETE_DIR_COMMAND: >+ return processDeleteDirCmd(con); > > case QUERY_SERVER_STATUS_COMMAND: > return processQueryServerStatusCmd(con); >@@ -591,3 +634,191 @@ > closeSocket(serverSocket); > return 0; > } >+ >+static int isSymLink(char *path) { >+ #ifndef _WIN32 >+ >+ struct stat statbuf; >+ int result = 0; >+ >+ result = lstat(path, &statbuf); >+ >+ if(result != 0) { >+ return -1; >+ } >+ >+ return S_ISLNK(statbuf.st_mode); >+ #else >+ // No sym links in Windows :) >+ return 0; >+ #endif >+} >+ >+#ifdef _WIN32 >+ #define PATH_SEPARATOR_STR "\\" >+ #define PATH_SEPARATOR_CHAR '\\' >+#else >+ #define PATH_SEPARATOR_STR "/" >+ #define PATH_SEPARATOR_CHAR '/' >+#endif >+ >+static int stripTrailingSlashIfExists(char * str) { >+ int r = 0; >+ >+ if(str == 0) return -1; >+ >+ r = strlen(str); >+ >+ if(str[r-1] == PATH_SEPARATOR_CHAR) { >+ str[r-1] = 0; >+ return 1; >+ } >+ >+ return 0; >+} >+ >+static int deleteFile(char * path ) { >+ int r = 0; >+ if(path == 0) { return -1; } >+ >+ r = remove(path); >+ >+ if(r != 0) { >+ return -1; >+ } >+ >+ return 0; >+} >+ >+ >+ >+static int recurseDeleteFilesInPath(char * path) { >+ char * localPath; >+ fileDirectoryPos *dp; >+ >+ char *currName; >+ char *newPath; >+ int r = 0; >+ int skipFile = 0; >+ >+ if(fileExists(path) != 1 || isDirectory(path) != 1) { >+ return -1; >+ } >+ >+ localPath = (char *) malloc(strlen(path)+1); >+ strcpy(localPath, path); >+ stripTrailingSlashIfExists(localPath); >+ >+ dp = fileOpenDir(localPath); >+ >+ if(dp != 0) { >+ >+ currName = getPathFromDirPos(dp); >+ >+ while (currName != 0) { >+ >+ // Skip the . and .. values >+ if(!strcmp(currName, ".")) { skipFile = 1; } >+ if(!strcmp(currName, "..")) { skipFile = 1; } >+ >+ if(!skipFile) { >+ >+ // len(localPath) + 1 (for path separator) + length of file name + 1 (for \0 string terminator) + 1 (for buffer) >+ newPath = (char *)malloc( strlen(localPath) + 1 + strlen(currName) + 1 + 1 ); >+ >+ sprintf(newPath, "%s%s%s", localPath, PATH_SEPARATOR_STR, currName); >+ >+ if(isDirectory(newPath) == 1) { >+ deleteDirectory(newPath); >+ } else { >+ deleteFile(newPath); >+ } >+ >+ free(newPath); >+ } >+ >+ if(advanceToNextDirPos(dp) != 0) { >+ currName = 0; >+ } else { >+ currName = getPathFromDirPos(dp); >+ } >+ skipFile = 0; >+ >+ } >+ >+ closeDirPos(dp); >+ >+ } >+ >+ free(localPath); >+ >+ return 0; >+ >+} >+ >+/** Note: This function will be passed to both regular directory paths, and symlinked directory paths */ >+int deleteDirectory(char * path) { >+ int pathLength = 0; >+ int r = 0; >+ >+ if(path == 0) { >+ return -1; >+ } >+ >+ // If the path is not a directory, or there was an error, return -1 >+ if(isDirectory(path) != 1) { >+ return -1; >+ } >+ >+ pathLength = strlen(path); >+ >+ // Safety check to ensure we are not being asked to delete the root of the file system >+ #ifdef _WIN32 >+ >+ // This matches any incidence of (drive-letter):(\), so, c:, d:, c:\, d:\, etc. >+ if( (pathLength == 2 || pathLength == 3) && ((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z') ) ) { >+ >+ if(path[1] == ':') { >+ return -1; >+ } >+ >+ } >+ >+ #endif >+ >+ // This matches either \ or / or . or .. or empty string >+ if(!strcmp(path, "/") || !strcmp(path, "\\") || !strcmp(path, ".") || !strcmp(path, "..") || !strcmp(path, "~") || !strcmp(path, "") ) { >+ return -1; >+ } >+ >+ >+ // Attempt to remove directory first -- this will succeed on either empty directories, or sym links >+ // Do not remove this -- this is to prevent recursion into the contents of symlinked dirs which shouldn't be deleted >+ r = rmdirDirectory(path); >+ if(r == 0) { >+ return 0; >+ } >+ >+ #ifndef _WIN32 >+ >+ // The symlink should have been removed by the above; we don't want to recurse it if it hasn't, so just return here. >+ if(isSymLink(path) == 1) { >+ return -1; >+ } >+ >+ #endif >+ >+ // We are assured at this point that path is a directory by the isDirectory check above >+ >+ recurseDeleteFilesInPath(path); >+ >+ r = rmdirDirectory(path); >+ >+ // If the operation reports to have succeeded, or the directory no longer exists, then return >+ if(r == 0) { >+ return 0; >+ } >+ >+ return r; >+ >+} >Index: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h,v >retrieving revision 1.2 >diff -u -r1.2 nativeFileServer.h >--- src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h 13 May 2008 15:51:45 -0000 1.2 >+++ src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h 8 Feb 2010 19:45:14 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008 Intel Corporation. >+ * Copyright (c) 2008, 2010 Intel Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -15,6 +15,11 @@ > #ifndef _NATIVE_FILE_SERVER > #define _NATIVE_FILE_SERVER > >+#ifdef _WIN32 >+ #define WIN32_LEAN_AND_MEAN >+ #include <windows.h> >+#endif >+ > #include <string.h> > > #ifdef _WIN32
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 296799
: 159204