lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lai...@apache.org
Subject lucenenet git commit: (1) Fixed the Fsync method. The using instruction was being used improperly.
Date Thu, 29 Jan 2015 01:12:25 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 25405e3ed -> 280b775df


(1) Fixed the Fsync method. The using instruction was being used improperly.

(2) Fixed the helper RmDir which was not working properly.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/280b775d
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/280b775d
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/280b775d

Branch: refs/heads/master
Commit: 280b775df2c175d0c8163aeb10510d24067207d1
Parents: 25405e3
Author: Guido Tagliavini Ponce <t-gupon@microsoft.com>
Authored: Mon Jan 26 17:42:30 2015 -0800
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Wed Jan 28 19:55:09 2015 -0500

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/IOUtils.cs             | 50 +++++++++++++-------
 .../core/Store/TestWindowsMMap.cs               | 16 +++++--
 2 files changed, 43 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/280b775d/src/Lucene.Net.Core/Util/IOUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/IOUtils.cs b/src/Lucene.Net.Core/Util/IOUtils.cs
index a1019b8..5fd50cb 100644
--- a/src/Lucene.Net.Core/Util/IOUtils.cs
+++ b/src/Lucene.Net.Core/Util/IOUtils.cs
@@ -456,30 +456,44 @@ namespace Lucene.Net.Util
             while (true)
             {
                 FileStream file = null;
-                using (file)
+                bool success = false;
+                try
+                {
+                    // If the file is a directory we have to open read-only, for regular
files we must open r/w for the fsync to have an effect.
+                    // See http://blog.httrack.com/blog/2013/11/15/everything-you-always-wanted-to-know-about-fsync/
+                    file = new FileStream(fileToSync,
+                        FileMode.Open, // We shouldn't create a file when syncing.
+                        // Java version uses FileChannel which doesn't create the file if
it doesn't already exist, 
+                        // so there should be no reason for attempting to create it in Lucene.Net.
+                        FileAccess.Write,
+                        FileShare.ReadWrite);
+                    //FileSupport.Sync(file);
+                    file.Flush(true);
+                    success = true;
+                }
+                catch (IOException e)
                 {
-                    try
+                    if (retryCount == 5)
                     {
-                        // If the file is a directory we have to open read-only, for regular
files we must open r/w for the fsync to have an effect.
-                        // See http://blog.httrack.com/blog/2013/11/15/everything-you-always-wanted-to-know-about-fsync/
-                        file = new FileStream(fileToSync, FileMode.OpenOrCreate,
-                            isDir ? FileAccess.Read : FileAccess.Write,
-                            isDir ? FileShare.Read : FileShare.ReadWrite);
-                        //FileSupport.Sync(file);
-                        file.Flush(true);
-                        return;
+                        throw;
                     }
-                    catch (IOException e)
-                    {
-                        if (retryCount == 5)
-                        {
-                            throw;
-                        }
 
-                        // Pause 5 msec
-                        Thread.Sleep(5);
+                    // Pause 5 msec
+                    Thread.Sleep(5);
+                }
+                finally
+                {
+                    if (file != null)
+                    {
+                        file.Dispose();
                     }
                 }
+
+                if (success)
+                {
+                    return;
+                }
+
                 retryCount++;
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/280b775d/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
index 217c851..f1ae0bb 100644
--- a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
@@ -75,7 +75,7 @@ namespace Lucene.Net.Store
             // may take some time until the files are finally dereferenced. So clean the
             // directory up front, or otherwise new IndexWriter will fail.
             var dirPath = CreateTempDir("testLuceneMmap");
-            RmDir(dirPath);
+            RmDir(dirPath.FullName);
             var dir = new MMapDirectory(dirPath, null);
 
             // plan to add a set of useful stopwords, consider changing some of the
@@ -102,17 +102,23 @@ namespace Lucene.Net.Store
                     }
                 }
 
-                RmDir(dirPath);
+                RmDir(dirPath.FullName);
             }
         }
 
-        private static void RmDir(DirectoryInfo dir)
+        private static void RmDir(string dir)
         {
-            if (!dir.Exists)
+            if (!System.IO.Directory.Exists(dir))
             {
                 return;
             }
-            dir.Delete(true);
+
+            foreach (string f in System.IO.Directory.GetFiles(dir))
+            {
+                System.IO.File.Delete(f);
+            }
+
+            System.IO.Directory.Delete(dir);
         }
     }
 }
\ No newline at end of file


Mime
View raw message