Return-Path: X-Original-To: apmail-lucenenet-commits-archive@www.apache.org Delivered-To: apmail-lucenenet-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A7EAF10547 for ; Thu, 29 Jan 2015 01:12:24 +0000 (UTC) Received: (qmail 70699 invoked by uid 500); 29 Jan 2015 01:12:25 -0000 Delivered-To: apmail-lucenenet-commits-archive@lucenenet.apache.org Received: (qmail 70673 invoked by uid 500); 29 Jan 2015 01:12:25 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 70664 invoked by uid 99); 29 Jan 2015 01:12:25 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jan 2015 01:12:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 151E3E03EE; Thu, 29 Jan 2015 01:12:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: laimis@apache.org To: commits@lucenenet.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: lucenenet git commit: (1) Fixed the Fsync method. The using instruction was being used improperly. Date: Thu, 29 Jan 2015 01:12:25 +0000 (UTC) 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 Authored: Mon Jan 26 17:42:30 2015 -0800 Committer: Laimonas Simutis 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