[Box Backup-commit] COMMIT r961 - box/chris/merge/lib/win32

subversion at fluffy.co.uk subversion at fluffy.co.uk
Mon Sep 4 01:03:28 BST 2006


Author: chris
Date: 2006-09-04 01:03:28 +0100 (Mon, 04 Sep 2006)
New Revision: 961

Modified:
   box/chris/merge/lib/win32/emu.cpp
Log:
(refs #3)

Emulated chdir, mkdir and unlink should handle file names in UTF-8 as well


Modified: box/chris/merge/lib/win32/emu.cpp
===================================================================
--- box/chris/merge/lib/win32/emu.cpp	2006-09-04 00:02:12 UTC (rev 960)
+++ box/chris/merge/lib/win32/emu.cpp	2006-09-04 00:03:28 UTC (rev 961)
@@ -1402,7 +1402,16 @@
 
 int emu_chdir(const char* pDirName)
 {
-	WCHAR* pBuffer = ConvertUtf8ToWideString(pDirName);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pDirName);
+
+	if (AbsPathWithUnicode.size() == 0)
+	{
+		// error already logged by ConvertPathToAbsoluteUnicode()
+		return -1;
+	}
+
+	WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
 	if (!pBuffer) return -1;
 	int result = SetCurrentDirectoryW(pBuffer);
 	delete [] pBuffer;
@@ -1420,7 +1429,7 @@
 		return NULL;
 	}
 
-	if (len > BufSize)
+	if ((int)len > BufSize)
 	{
 		errno = ENAMETOOLONG;
 		return NULL;
@@ -1457,7 +1466,16 @@
 
 int emu_mkdir(const char* pPathName)
 {
-	WCHAR* pBuffer = ConvertToWideString(pPathName, CP_UTF8);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pPathName);
+
+	if (AbsPathWithUnicode.size() == 0)
+	{
+		// error already logged by ConvertPathToAbsoluteUnicode()
+		return -1;
+	}
+
+	WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
 	if (!pBuffer)
 	{
 		return -1;
@@ -1477,18 +1495,45 @@
 
 int emu_unlink(const char* pFileName)
 {
-	WCHAR* pBuffer = ConvertToWideString(pFileName, CP_UTF8);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pFileName);
+
+	if (AbsPathWithUnicode.size() == 0)
+	{
+		// error already logged by ConvertPathToAbsoluteUnicode()
+		return -1;
+	}
+
+	WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
 	if (!pBuffer)
 	{
 		return -1;
 	}
 
 	BOOL result = DeleteFileW(pBuffer);
+	DWORD err = GetLastError();
 	delete [] pBuffer;
 
 	if (!result)
 	{
-		errno = EACCES;
+		if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND)
+		{
+			errno = ENOENT;
+		}
+		else if (err == ERROR_SHARING_VIOLATION)
+		{
+			errno = EBUSY;
+		}
+		else if (err == ERROR_ACCESS_DENIED)
+		{
+			errno = EACCES;
+		}
+		else
+		{
+			::syslog(LOG_WARNING, "Failed to delete file "
+				"'%s': error %d", pFileName, (int)err);
+			errno = ENOSYS;
+		}
 		return -1;
 	}
 




More information about the Boxbackup-commit mailing list