[llvm-commits] [llvm] r122883 - /llvm/trunk/lib/Support/Windows/PathV2.inc

Michael J. Spencer bigcheesegs at gmail.com
Wed Jan 5 08:39:30 PST 2011


Author: mspencer
Date: Wed Jan  5 10:39:30 2011
New Revision: 122883

URL: http://llvm.org/viewvc/llvm-project?rev=122883&view=rev
Log:
Support/Windows/PathV2: Make directory iteration ignore . and ..

Modified:
    llvm/trunk/lib/Support/Windows/PathV2.inc

Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=122883&r1=122882&r2=122883&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Wed Jan  5 10:39:30 2011
@@ -639,16 +639,30 @@
   if (!FindHandle)
     return windows_error(::GetLastError());
 
+  size_t FilenameLen = ::wcslen(FirstFind.cFileName);
+  while ((FilenameLen == 1 && FirstFind.cFileName[0] == L'.') ||
+         (FilenameLen == 2 && FirstFind.cFileName[0] == L'.' &&
+                              FirstFind.cFileName[1] == L'.'))
+    if (!::FindNextFileW(FindHandle, &FirstFind)) {
+      error_code ec = windows_error(::GetLastError());
+      // Check for end.
+      if (ec == windows_error::no_more_files)
+        return directory_iterator_destruct(it);
+      return ec;
+    } else
+      FilenameLen = ::wcslen(FirstFind.cFileName);
+
   // Construct the current directory entry.
-  SmallString<128> directory_entry_path_utf8;
+  SmallString<128> directory_entry_name_utf8;
   if (error_code ec = UTF16ToUTF8(FirstFind.cFileName,
                                   ::wcslen(FirstFind.cFileName),
-                                  directory_entry_path_utf8))
+                                  directory_entry_name_utf8))
     return ec;
 
   it.IterationHandle = intptr_t(FindHandle.take());
-  it.CurrentEntry = directory_entry(path);
-  it.CurrentEntry.replace_filename(Twine(directory_entry_path_utf8));
+  SmallString<128> directory_entry_path(path);
+  path::append(directory_entry_path, directory_entry_name_utf8.str());
+  it.CurrentEntry = directory_entry(directory_entry_path.str());
 
   return success;
 }
@@ -672,6 +686,12 @@
     return ec;
   }
 
+  size_t FilenameLen = ::wcslen(FindData.cFileName);
+  if ((FilenameLen == 1 && FindData.cFileName[0] == L'.') ||
+      (FilenameLen == 2 && FindData.cFileName[0] == L'.' &&
+                           FindData.cFileName[1] == L'.'))
+    return directory_iterator_increment(it);
+
   SmallString<128> directory_entry_path_utf8;
   if (error_code ec = UTF16ToUTF8(FindData.cFileName,
                                   ::wcslen(FindData.cFileName),





More information about the llvm-commits mailing list