Fix .. in path names
Mike McCormack
mike at codeweavers.com
Wed Jan 28 08:25:55 CST 2004
Hi,
This patch fixes the problem with non-existant directories and .. in
pathnames. (and it makes my test case work, Dimi!)
Mike
ChangeLog:
* fix handling of .. in pathes and add a test case for it
-------------- next part --------------
Index: files/dos_fs.c
===================================================================
RCS file: /home/wine/wine/files/dos_fs.c,v
retrieving revision 1.148
diff -u -r1.148 dos_fs.c
--- files/dos_fs.c 23 Jan 2004 01:51:33 -0000 1.148
+++ files/dos_fs.c 28 Jan 2004 13:21:53 -0000
@@ -1023,7 +1023,7 @@
/***********************************************************************
- * DOSFS_GetFullName
+ * DOSFS_GetFullNameNoDots
*
* Convert a file name (DOS or mixed DOS/Unix format) to a valid
* Unix name / short DOS name pair.
@@ -1032,7 +1032,8 @@
* The buffers pointed to by 'long_buf' and 'short_buf' must be
* at least MAX_PATHNAME_LEN long.
*/
-BOOL DOSFS_GetFullName( LPCWSTR name, BOOL check_last, DOS_FULL_NAME *full )
+static BOOL DOSFS_GetFullNameNoDots( LPCWSTR name, BOOL check_last,
+ DOS_FULL_NAME *full )
{
BOOL found;
UINT flags;
@@ -1171,6 +1172,26 @@
return TRUE;
}
+/***********************************************************************
+ * DOSFS_GetFullName
+ *
+ * Clean up the path name... before trying to convert it to a unix path
+ */
+BOOL DOSFS_GetFullName( LPCWSTR name, BOOL check_last, DOS_FULL_NAME *full )
+{
+ WCHAR buffer[MAX_PATH], *dummy;
+
+ TRACE("%s\n", debugstr_w(name));
+
+ /* don't mess with unix path names */
+ if( strchrW(name,'/') )
+ return DOSFS_GetFullNameNoDots( name, check_last, full );
+
+ if(!GetFullPathNameW( name, MAX_PATH, buffer, &dummy))
+ return DOSFS_GetFullNameNoDots( name, check_last, full );
+
+ return DOSFS_GetFullNameNoDots( buffer, check_last, full );
+}
/***********************************************************************
* wine_get_unix_file_name (KERNEL32.@) Not a Windows API
Index: dlls/kernel/tests/file.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/file.c,v
retrieving revision 1.29
diff -u -r1.29 file.c
--- dlls/kernel/tests/file.c 27 Jan 2004 20:13:03 -0000 1.29
+++ dlls/kernel/tests/file.c 28 Jan 2004 13:21:53 -0000
@@ -979,6 +979,71 @@
ok( DeleteFileA( filename ), "DeleteFile failed after map\n" );
}
+static void test_Dots()
+{
+ DWORD r;
+ HANDLE hFile;
+ CHAR cwd[MAX_PATH], buffer[MAX_PATH];
+
+ ok( GetCurrentDirectory( MAX_PATH, cwd ), "can't get cwd");
+
+ DeleteFile("a.exe");
+
+ hFile = CreateFile("a.exe", GENERIC_READ|GENERIC_WRITE, 0, NULL,
+ CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0);
+ ok( hFile != INVALID_HANDLE_VALUE, "Failed to create file");
+ ok( CloseHandle( hFile ), "CloseHandle failed");
+
+ r = GetFileAttributes("some_non_dir\\..\\a.exe");
+ ok(r == FILE_ATTRIBUTE_ARCHIVE, "GetFileAttributes failed");
+
+ /* try query a file */
+ hFile = CreateFile("blah\\..\\a.exe", GENERIC_READ,
+ FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+
+ ok( hFile != INVALID_HANDLE_VALUE, "RO open failed");
+ ok(CloseHandle(hFile), "couldn't close\n");
+
+ ok( DeleteFile("bogus_dir\\..\\a.exe"), "failed to delete file");
+
+ /*
+ * make sure we're at least one directory up
+ * then create a file in our directory
+ */
+ ok( CreateDirectory("abcdef\\..\\testdir1",NULL), "createdir failed");
+
+ /* now change into that directory */
+ ok( SetCurrentDirectory("abcdef\\..\\testdir1"), "set cwd failed");
+
+ /* create a file in it */
+ hFile = CreateFile("..\\testdir1\\xyz.txt",
+ GENERIC_READ |GENERIC_WRITE,
+ 0, NULL, CREATE_ALWAYS, 0, NULL);
+ ok( hFile != INVALID_HANDLE_VALUE, "couldn't create xyz.txt");
+ ok(CloseHandle(hFile), "couldn't close\n");
+
+ /* go down one directory */
+ ok( SetCurrentDirectory("blah\\..\\.."), "set cwd failed");
+
+ ok( GetCurrentDirectory( MAX_PATH, buffer ), "can't get cwd");
+ todo_wine
+ {
+ ok( !strcmp( buffer, cwd ), "should be back in the original cwd" );
+ SetCurrentDirectory(cwd); /* remove this when above works */
+ }
+
+ /*
+ * try delete the directory
+ * should fail... there's a file in there
+ */
+ ok( !RemoveDirectory("abcdef\\..\\testdir1"),"remove worked");
+
+ ok( DeleteFile("blah123\\..\\boohoo\\..\\testdir1\\xyz.txt"), "del failed");
+
+ /* now it's empty, the delete should work properly */
+ ok( RemoveDirectory("abcdef\\..\\testdir1"),"remove failed");
+}
+
START_TEST(file)
{
test__hread( );
@@ -1003,4 +1068,5 @@
test_LockFile();
test_offset_in_overlapped_structure();
test_MapFile();
+ test_Dots();
}
More information about the wine-patches
mailing list