[前][次][番号順一覧][スレッド一覧]

ruby-changes:37577

From: nobu <ko1@a...>
Date: Fri, 20 Feb 2015 17:19:36 +0900 (JST)
Subject: [ruby-changes:37577] nobu:r49658 (trunk): win32.c: volume serial numbers

nobu	2015-02-20 17:19:26 +0900 (Fri, 20 Feb 2015)

  New Revision: 49658

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49658

  Log:
    win32.c: volume serial numbers
    
    * win32/win32.c (different_device_p): compare by volume serial
      numbers, not by path names.

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49657)
+++ ChangeLog	(revision 49658)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Feb 20 17:19:23 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (different_device_p): compare by volume serial
+	  numbers, not by path names.
+
 Thu Feb 19 01:58:10 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32/file.c (rb_file_expand_path_internal): neither the drive
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 49657)
+++ win32/win32.c	(revision 49658)
@@ -4702,28 +4702,28 @@ rb_w32_getenv(const char *name) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4702
 }
 
 /* License: Ruby's */
+static DWORD
+get_volume_serial_number(const WCHAR *path)
+{
+    const DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+    const DWORD creation = OPEN_EXISTING;
+    const DWORD flags = FILE_FLAG_BACKUP_SEMANTICS;
+    BY_HANDLE_FILE_INFORMATION st = {0};
+    HANDLE h = CreateFileW(path, 0, share_mode, NULL, creation, flags, NULL);
+    BOOL ret;
+
+    if (h == INVALID_HANDLE_VALUE) return 0;
+    ret = GetFileInformationByHandle(h, &st);
+    CloseHandle(h);
+    if (!ret) return 0;
+    return st.dwVolumeSerialNumber;
+}
+
+/* License: Ruby's */
 static int
 different_device_p(const WCHAR *oldpath, const WCHAR *newpath)
 {
-    WCHAR oldfullpath[_MAX_PATH], newfullpath[_MAX_PATH];
-    DWORD oldlen, newlen;
-
-    newlen = GetFullPathNameW(newpath, numberof(newfullpath), newfullpath, NULL);
-    if (newlen <= 1) return 0;
-    oldlen = GetFullPathNameW(oldpath, numberof(oldfullpath), oldfullpath, NULL);
-    if (oldlen <= 1) return 0;
-    if (newfullpath[1] == L':') {
-	if (oldfullpath[1] != L':') return 1;
-	return newfullpath[0] != oldfullpath[0];
-    }
-    if (newfullpath[0] != L'\\' || newfullpath[1] != L'\\') return 0;
-    if (oldfullpath[0] != L'\\' || oldfullpath[1] != L'\\') return 0;
-    if (!(newpath = wcschr(newfullpath+2, L'\\'))) return 0;
-    if (!(newpath = wcschr(newpath+1, L'\\'))) return 0;
-    if (!(oldpath = wcschr(oldfullpath+2, L'\\'))) return 0;
-    if (!(oldpath = wcschr(oldpath+1, L'\\'))) return 0;
-    if (newpath - newfullpath != oldpath - oldfullpath) return 1;
-    return wcsncmp(newfullpath, oldfullpath, oldpath - oldfullpath) != 0;
+    return get_volume_serial_number(oldpath) != get_volume_serial_number(newpath);
 }
 
 /* License: Artistic or GPL */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]