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

subversion at fluffy.co.uk subversion at fluffy.co.uk
Mon Sep 4 00:48:34 BST 2006


Author: chris
Date: 2006-09-04 00:48:34 +0100 (Mon, 04 Sep 2006)
New Revision: 953

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

Always fill in st_uid, st_gid and st_nlink

Return zero size for directories

Improved emulation of Unix file modes (helps when restoring Windows files
on Unix)


Modified: box/chris/merge/lib/win32/emu.cpp
===================================================================
--- box/chris/merge/lib/win32/emu.cpp	2006-09-03 23:46:11 UTC (rev 952)
+++ box/chris/merge/lib/win32/emu.cpp	2006-09-03 23:48:34 UTC (rev 953)
@@ -617,43 +617,57 @@
 	st->st_atime = ConvertFileTimeToTime_t(&fi.ftLastAccessTime);
 	st->st_mtime = ConvertFileTimeToTime_t(&fi.ftLastWriteTime);
 
-	// size of the file
-	LARGE_INTEGER st_size;
-	if (!GetFileSizeEx(hdir, &st_size))
+	if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
 	{
-		::syslog(LOG_WARNING, "Failed to get file size: error %d",
-			GetLastError());
-		errno = EACCES;
-		return -1;
+		st->st_size = 0;
 	}
+	else
+	{
+		// size of the file
+		LARGE_INTEGER st_size;
+		memset(&st_size, 0, sizeof(st_size));
 
-	conv.HighPart = st_size.HighPart;
-	conv.LowPart = st_size.LowPart;
-	st->st_size = (_off_t)conv.QuadPart;
+		if (!GetFileSizeEx(hdir, &st_size))
+		{
+			::syslog(LOG_WARNING, "Failed to get file size: "
+				"error %d", GetLastError());
+			errno = EACCES;
+			return -1;
+		}
 
-	//the mode of the file
-	st->st_mode = 0;
-	//DWORD res = GetFileAttributes((LPCSTR)tmpStr.c_str());
+		conv.HighPart = st_size.HighPart;
+		conv.LowPart = st_size.LowPart;
+		st->st_size = (_off_t)conv.QuadPart;
+	}
 
-	if (INVALID_FILE_ATTRIBUTES != fi.dwFileAttributes)
+	// at the mo
+	st->st_uid = 0;
+	st->st_gid = 0;
+	st->st_nlink = 1;
+
+	// the mode of the file
+	// mode zero will make it impossible to restore on Unix
+	// (no access to anybody, including the owner).
+	// we'll fake a sensible mode:
+	// all objects get user read (0400)
+	// if it's a directory it gets user execute (0100)
+	// if it's not read-only it gets user write (0200)
+	st->st_mode = S_IREAD;
+
+	if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
 	{
-		if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-		{
-			st->st_mode |= S_IFDIR;
-		}
-		else
-		{
-			st->st_mode |= S_IFREG;
-		}
+		st->st_mode |= S_IFDIR | S_IEXEC;
 	}
 	else
 	{
-		::syslog(LOG_WARNING, "Failed to get file attributes: "
-			"error %d", GetLastError());
-		errno = EACCES;
-		return -1;
+		st->st_mode |= S_IFREG;
 	}
 
+	if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
+	{
+		st->st_mode |= S_IWRITE;
+	}
+
 	return 0;
 }
 




More information about the Boxbackup-commit mailing list