You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/09/25 11:52:25 UTC
[1/8] lucenenet git commit: Lucene.Net.Support.IO.FileSupport:
Removed unused GetFiles(), GetLuceneIndexFiles(), and Sync() methods
Repository: lucenenet
Updated Branches:
refs/heads/master 64a467ac3 -> 8866a3afd
Lucene.Net.Support.IO.FileSupport: Removed unused GetFiles(), GetLuceneIndexFiles(), and Sync() methods
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/4467e6ed
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/4467e6ed
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/4467e6ed
Branch: refs/heads/master
Commit: 4467e6ed7b04916dab9c937769a7f78d8dda9d70
Parents: 64a467a
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sat Sep 23 19:27:54 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sat Sep 23 19:27:54 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Support/IO/FileSupport.cs | 98 ---------------------------
1 file changed, 98 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4467e6ed/src/Lucene.Net/Support/IO/FileSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/IO/FileSupport.cs b/src/Lucene.Net/Support/IO/FileSupport.cs
index 5cfe641..bac1e5a 100644
--- a/src/Lucene.Net/Support/IO/FileSupport.cs
+++ b/src/Lucene.Net/Support/IO/FileSupport.cs
@@ -19,11 +19,9 @@
*
*/
-using Lucene.Net.Util;
using System;
using System.IO;
using System.Linq;
-using System.Runtime.CompilerServices;
using System.Text;
namespace Lucene.Net.Support.IO
@@ -36,102 +34,6 @@ namespace Lucene.Net.Support.IO
private static readonly object _lock = new object();
/// <summary>
- /// Returns an array of abstract pathnames representing the files and directories of the specified path.
- /// </summary>
- /// <param name="path">The abstract pathname to list it childs.</param>
- /// <returns>An array of abstract pathnames childs of the path specified or null if the path is not a directory</returns>
- public static System.IO.FileInfo[] GetFiles(System.IO.FileInfo path)
- {
- if ((path.Attributes & FileAttributes.Directory) > 0)
- {
- String[] fullpathnames = Directory.GetFileSystemEntries(path.FullName);
- System.IO.FileInfo[] result = new System.IO.FileInfo[fullpathnames.Length];
- for (int i = 0; i < result.Length; i++)
- result[i] = new System.IO.FileInfo(fullpathnames[i]);
- return result;
- }
- else
- return null;
- }
-
- // TODO: This filesupport thing is silly. Same goes with _TestUtil's RMDir.
- // If we're removing a directory
- public static System.IO.FileInfo[] GetFiles(System.IO.DirectoryInfo path)
- {
- return GetFiles(new FileInfo(path.FullName));
- }
-
- ///// <summary>
- ///// Returns a list of files in a give directory.
- ///// </summary>
- ///// <param name="fullName">The full path name to the directory.</param>
- ///// <param name="indexFileNameFilter"></param>
- ///// <returns>An array containing the files.</returns>
- //public static System.String[] GetLuceneIndexFiles(System.String fullName,
- // Index.IndexFileNameFilter indexFileNameFilter)
- //{
- // System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(fullName);
- // System.Collections.ArrayList list = new System.Collections.ArrayList();
- // foreach (System.IO.FileInfo fInfo in dInfo.GetFiles())
- // {
- // if (indexFileNameFilter.Accept(fInfo, fInfo.Name) == true)
- // {
- // list.Add(fInfo.Name);
- // }
- // }
- // System.String[] retFiles = new System.String[list.Count];
- // list.CopyTo(retFiles);
- // return retFiles;
- //}
-
- // Disable the obsolete warning since we must use FileStream.Handle
- // because Mono does not support FileSystem.SafeFileHandle at present.
-#pragma warning disable 618
-
- /// <summary>
- /// Flushes the specified file stream. Ensures that all buffered
- /// data is actually written to the file system.
- /// </summary>
- /// <param name="fileStream">The file stream.</param>
- public static void Sync(System.IO.FileStream fileStream)
- {
- if (fileStream == null)
- throw new ArgumentNullException("fileStream");
-
- fileStream.Flush(true);
-
- if (Constants.WINDOWS)
- {
-#if NETSTANDARD
- // Getting the SafeFileHandle property automatically flushes the
- // stream: https://msdn.microsoft.com/en-us/library/system.io.filestream.safefilehandle(v=vs.110).aspx
- var handle = fileStream.SafeFileHandle;
-#else
- if (!FlushFileBuffers(fileStream.Handle))
- throw new IOException();
-#endif
- }
- //else if (Constants.LINUX)
- //{
- // if (fsync(fileStream.Handle) != IntPtr.Zero)
- // throw new System.IO.IOException();
- //}
- //else
- //{
- // throw new NotImplementedException();
- //}
- }
-
-#pragma warning restore 618
-
- //[System.Runtime.InteropServices.DllImport("libc")]
- //extern static IntPtr fsync(IntPtr fd);
-
- [System.Runtime.InteropServices.DllImport("kernel32.dll")]
- extern static bool FlushFileBuffers(IntPtr hFile);
-
-
- /// <summary>
/// Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.
/// If this method returns successfully then it is guaranteed that:
/// <list type="number">
[2/8] lucenenet git commit: Lucene.Net.Support.IO.FileSupport: Made
class static
Posted by ni...@apache.org.
Lucene.Net.Support.IO.FileSupport: Made class static
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/06f349a7
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/06f349a7
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/06f349a7
Branch: refs/heads/master
Commit: 06f349a7707e4e460272fd30388e4438fa990bc0
Parents: 4467e6e
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sat Sep 23 19:28:37 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sat Sep 23 19:28:37 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Support/IO/FileSupport.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/06f349a7/src/Lucene.Net/Support/IO/FileSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/IO/FileSupport.cs b/src/Lucene.Net/Support/IO/FileSupport.cs
index bac1e5a..491ee35 100644
--- a/src/Lucene.Net/Support/IO/FileSupport.cs
+++ b/src/Lucene.Net/Support/IO/FileSupport.cs
@@ -29,7 +29,7 @@ namespace Lucene.Net.Support.IO
/// <summary>
/// Represents the methods to support some operations over files.
/// </summary>
- public class FileSupport
+ public static class FileSupport
{
private static readonly object _lock = new object();
[3/8] lucenenet git commit: Lucene.Net.Support.IO.FileSupport: Fixed
several issues with CreateTempFile()
Posted by ni...@apache.org.
Lucene.Net.Support.IO.FileSupport: Fixed several issues with CreateTempFile()
a) Added overload with no directory
b) Changed implementation to use Path.GetInvalidFileNameCharacters() instead of Path.GetInvalidPathCharacters() when checking prefix and suffix
c) Create the temp directory if it doesn't already exist d) Use FileStream instead of File.WriteAllText() or the correct exception isn't thrown when the file exists
d) On Windows, we check the HResult of the exception instead of checking File.Exists() to determine whether the IOException that was thrown is because the file already exists
e) Corrected documentation
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/5065f10c
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/5065f10c
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/5065f10c
Branch: refs/heads/master
Commit: 5065f10c015c31e84eaed434134f7cb13c95bf3a
Parents: 06f349a
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sun Sep 24 16:25:18 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sun Sep 24 16:25:18 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Support/IO/FileSupport.cs | 184 ++++++++++++++++----------
1 file changed, 115 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5065f10c/src/Lucene.Net/Support/IO/FileSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/IO/FileSupport.cs b/src/Lucene.Net/Support/IO/FileSupport.cs
index 491ee35..99ac644 100644
--- a/src/Lucene.Net/Support/IO/FileSupport.cs
+++ b/src/Lucene.Net/Support/IO/FileSupport.cs
@@ -1,24 +1,4 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
+using Lucene.Net.Util;
using System;
using System.IO;
using System.Linq;
@@ -26,87 +6,153 @@ using System.Text;
namespace Lucene.Net.Support.IO
{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/// <summary>
/// Represents the methods to support some operations over files.
/// </summary>
public static class FileSupport
{
- private static readonly object _lock = new object();
+ private static int ERROR_FILE_EXISTS = 0x0050;
/// <summary>
- /// Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.
+ /// Creates a new empty file in a random subdirectory of <see cref="Path.GetTempPath()"/>, using the given prefix and
+ /// suffix strings to generate its name.
+ /// </summary>
+ /// <remarks>
/// If this method returns successfully then it is guaranteed that:
/// <list type="number">
/// <item><description>The file denoted by the returned abstract pathname did not exist before this method was invoked, and</description></item>
/// <item><description>Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.</description></item>
/// </list>
- /// This method provides only part of a temporary-file facility.To arrange for a file created by this method to be deleted automatically, use the deleteOnExit() method.
- /// The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail". The suffix argument may be null, in which case the suffix ".tmp" will be used.
- /// To create the new file, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform.If the prefix is too long then it will be truncated, but its first three characters will always be preserved.If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved.Once these adjustments have been made the name of the new file will be generated by concatenating the prefix, five or more internally-generated characters, and the suffix.
- /// If the directory argument is null then the system-dependent default temporary-file directory will be used.The default temporary-file directory is specified by the system property java.io.tmpdir.On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "C:\\WINNT\\TEMP". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the temporary directory used by this method.
- ///
- /// Ported over from the java.io.File class. Used by the Analysis.Hunspell.Directory
- /// class, but this can probably be removed when that class is upgraded to a more recent
- /// version of lucene, where it uses the lucene Store.Directory class to create a temporary
- /// file.
+ /// This method provides only part of a temporary-file facility. However, the file will not be deleted automatically,
+ /// it must be deleted by the caller.
+ /// <para/>
+ /// The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful
+ /// string such as "hjb" or "mail".
+ /// <para/>
+ /// The suffix argument may be null, in which case a random suffix will be used.
+ /// <para/>
+ /// Both prefix and suffix must be provided with valid characters for the underlying system, as specified by
+ /// <see cref="Path.GetInvalidFileNameChars()"/>.
+ /// <para/>
+ /// If the directory argument is null then the system-dependent default temporary-file directory will be used,
+ /// with a random subdirectory name. The default temporary-file directory is specified by the
+ /// <see cref="Path.GetTempPath()"/> method. On UNIX systems the default value of this property is typically
+ /// "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "C:\\Users\\[UserName]\\AppData\Local\Temp".
+ /// </remarks>
+ /// <param name="prefix">The prefix string to be used in generating the file's name; must be at least three characters long</param>
+ /// <param name="suffix">The suffix string to be used in generating the file's name; may be null, in which case a random suffix will be generated</param>
+ /// <returns>A <see cref="FileInfo"/> instance representing the temp file that was created.</returns>
+ public static FileInfo CreateTempFile(string prefix, string suffix)
+ {
+ return CreateTempFile(prefix, suffix, null);
+ }
+
+ /// <summary>
+ /// Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.
/// </summary>
+ /// <remarks>
+ /// If this method returns successfully then it is guaranteed that:
+ /// <list type="number">
+ /// <item><description>The file denoted by the returned abstract pathname did not exist before this method was invoked, and</description></item>
+ /// <item><description>Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.</description></item>
+ /// </list>
+ /// This method provides only part of a temporary-file facility. However, the file will not be deleted automatically,
+ /// it must be deleted by the caller.
+ /// <para/>
+ /// The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful
+ /// string such as "hjb" or "mail".
+ /// <para/>
+ /// The suffix argument may be null, in which case a random suffix will be used.
+ /// <para/>
+ /// Both prefix and suffix must be provided with valid characters for the underlying system, as specified by
+ /// <see cref="Path.GetInvalidFileNameChars()"/>.
+ /// <para/>
+ /// If the directory argument is null then the system-dependent default temporary-file directory will be used,
+ /// with a random subdirectory name. The default temporary-file directory is specified by the
+ /// <see cref="Path.GetTempPath()"/> method. On UNIX systems the default value of this property is typically
+ /// "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "C:\\Users\\[UserName]\\AppData\Local\Temp".
+ /// </remarks>
/// <param name="prefix">The prefix string to be used in generating the file's name; must be at least three characters long</param>
/// <param name="suffix">The suffix string to be used in generating the file's name; may be null, in which case a random suffix will be generated</param>
/// <param name="directory">The directory in which the file is to be created, or null if the default temporary-file directory is to be used</param>
- /// <returns></returns>
+ /// <returns>A <see cref="FileInfo"/> instance representing the temp file that was created.</returns>
public static FileInfo CreateTempFile(string prefix, string suffix, DirectoryInfo directory)
{
- lock (_lock)
- {
- if (string.IsNullOrEmpty(prefix))
- throw new ArgumentNullException("prefix");
- if (prefix.Length < 3)
- throw new ArgumentException("Prefix string too short");
+ if (string.IsNullOrEmpty(prefix))
+ throw new ArgumentNullException("prefix");
+ if (prefix.Length < 3)
+ throw new ArgumentException("Prefix string too short");
- // Ensure the strings passed don't contain invalid characters
- char[] invalid = Path.GetInvalidPathChars();
+ // Ensure the strings passed don't contain invalid characters
+ char[] invalid = Path.GetInvalidFileNameChars();
- if (prefix.ToCharArray().Intersect(invalid).Any())
- throw new ArgumentException(string.Format("Prefix contains invalid characters. You may not use any of '{0}'", string.Join(", ", invalid)));
- if (suffix != null && suffix.ToCharArray().Intersect(invalid).Any())
- throw new ArgumentException(string.Format("Suffix contains invalid characters. You may not use any of '{0}'", string.Join(", ", invalid)));
+ if (prefix.ToCharArray().Intersect(invalid).Any())
+ throw new ArgumentException(string.Format("Prefix contains invalid characters. You may not use any of '{0}'", string.Join(", ", invalid)));
+ if (suffix != null && suffix.ToCharArray().Intersect(invalid).Any())
+ throw new ArgumentException(string.Format("Suffix contains invalid characters. You may not use any of '{0}'", string.Join(", ", invalid)));
- // If no directory supplied, create one.
- if (directory == null)
+ // If no directory supplied, create one.
+ if (directory == null)
+ {
+ directory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));
+ }
+ // Ensure the directory exists (this does nothing if it already exists, although may throw exceptions in cases where permissions are changed)
+ directory.Create();
+ string fileName = string.Empty;
+
+ while (true)
+ {
+ fileName = NewTempFileName(prefix, suffix, directory);
+
+ if (File.Exists(fileName))
{
- directory = new DirectoryInfo(Path.GetTempPath());
+ continue;
}
- string fileName = string.Empty;
- while (true)
+ try
{
- fileName = NewTempFileName(prefix, suffix, directory);
-
- if (File.Exists(fileName))
+ // Create the file, and close it immediately
+ using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
- continue;
+ break;
}
-
- try
+ }
+ catch (IOException e)
+ {
+ // If the error was because the file exists, try again.
+ // On Windows, we can rely on the constant, but we need to fallback
+ // to doing a physical file check to be portable across platforms.
+ if (Constants.WINDOWS && (e.HResult & 0xFFFF) == ERROR_FILE_EXISTS)
{
- // Create the file, and close it immediately
- File.WriteAllText(fileName, string.Empty, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) /* No BOM */);
- break;
+ continue;
}
- catch (IOException e)
+ else if (!Constants.WINDOWS && File.Exists(fileName))
{
- // If the error was because the file exists, try again
- if (File.Exists(fileName))
- {
- continue;
- }
-
- // else rethrow it
- throw e;
+ continue;
}
+
+ // else rethrow it
+ throw;
}
- return new FileInfo(fileName);
}
+ return new FileInfo(fileName);
}
/// <summary>
[4/8] lucenenet git commit: Lucene.Net.Support.IO.FileSupport: Added
GetCanonicalPath() method + tests
Posted by ni...@apache.org.
Lucene.Net.Support.IO.FileSupport: Added GetCanonicalPath() method + tests
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/8b7b9cb6
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/8b7b9cb6
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/8b7b9cb6
Branch: refs/heads/master
Commit: 8b7b9cb6d02292e6d31330c0153ae1b975ecbae0
Parents: 5065f10
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Sep 25 00:25:44 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Sep 25 00:25:44 2017 +0700
----------------------------------------------------------------------
.../Support/IO/TestFileSupport.cs | 216 +++++++++++++++++++
src/Lucene.Net/Support/IO/FileSupport.cs | 124 +++++++++++
2 files changed, 340 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8b7b9cb6/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs b/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs
new file mode 100644
index 0000000..b5ce877
--- /dev/null
+++ b/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs
@@ -0,0 +1,216 @@
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+using System.Globalization;
+using System.IO;
+
+namespace Lucene.Net.Support.IO
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ public class TestFileSupport : LuceneTestCase
+ {
+ private static String platformId = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.Replace('.', '-');
+
+ /** Location to store tests in */
+ private DirectoryInfo tempDirectory;
+
+ public override void SetUp()
+ {
+ base.SetUp();
+ tempDirectory = CreateTempDir(this.GetType().Name);
+ }
+
+ public override void TearDown()
+ {
+ if (tempDirectory != null)
+ {
+ Directory.Delete(tempDirectory.FullName, true);
+ tempDirectory = null;
+ }
+ base.TearDown();
+ }
+
+ [Test, LuceneNetSpecific]
+ public void TestCreateRandomFile()
+ {
+ var dir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "testrandomfile"));
+
+ var file1 = FileSupport.CreateTempFile("foo", "bar", dir);
+ var file2 = FileSupport.CreateTempFile("foo", "bar", dir);
+
+ Assert.AreNotEqual(file1.FullName, file2.FullName);
+ }
+
+ [Test, LuceneNetSpecific]
+ public void TestGetCanonicalPath()
+ {
+ // Should work for Unix/Windows.
+ String dots = "..";
+ String @base = tempDirectory.GetCanonicalPath();
+ @base = addTrailingSlash(@base);
+ FileInfo f = new FileInfo(Path.Combine(@base, "temp.tst"));
+
+ assertEquals("Test 1: Incorrect Path Returned.", @base + "temp.tst", f
+ .GetCanonicalPath());
+ f = new FileInfo(@base + "Temp" + Path.DirectorySeparatorChar + dots + Path.DirectorySeparatorChar + "temp.tst");
+ assertEquals("Test 2: Incorrect Path Returned.", @base + "temp.tst", f
+ .GetCanonicalPath());
+
+
+ // Finding a non-existent directory for tests 3 and 4
+ // This is necessary because getCanonicalPath is case sensitive and
+ // could cause a failure in the test if the directory exists but with
+ // different case letters (e.g "Temp" and "temp")
+ int dirNumber = 1;
+ bool dirExists = true;
+ DirectoryInfo dir1 = new DirectoryInfo(Path.Combine(@base, dirNumber.ToString(CultureInfo.InvariantCulture)));
+ while (dirExists)
+ {
+ if (dir1.Exists)
+ {
+ dirNumber++;
+ dir1 = new DirectoryInfo(Path.Combine(@base, dirNumber.ToString(CultureInfo.InvariantCulture)));
+ }
+ else
+ {
+ dirExists = false;
+ }
+ }
+ f = new FileInfo(@base + dirNumber + Path.DirectorySeparatorChar + dots + Path.DirectorySeparatorChar + dirNumber
+ + Path.DirectorySeparatorChar + "temp.tst");
+ assertEquals("Test 3: Incorrect Path Returned.", @base + dirNumber
+ + Path.DirectorySeparatorChar + "temp.tst", f.GetCanonicalPath());
+ f = new FileInfo(@base + dirNumber + Path.DirectorySeparatorChar + "Temp" + Path.DirectorySeparatorChar + dots + Path.DirectorySeparatorChar
+ + "Test" + Path.DirectorySeparatorChar + "temp.tst");
+ assertEquals("Test 4: Incorrect Path Returned.", @base + dirNumber
+ + Path.DirectorySeparatorChar + "Test" + Path.DirectorySeparatorChar + "temp.tst", f.GetCanonicalPath());
+
+ f = new FileInfo(@base + "1234.567");
+ assertEquals("Test 5: Incorrect Path Returned.", @base + "1234.567", f
+ .GetCanonicalPath());
+
+ // Test for long file names on Windows
+ bool onWindows = (Path.DirectorySeparatorChar == '\\');
+ if (onWindows)
+ {
+ DirectoryInfo testdir = new DirectoryInfo(Path.Combine(@base, "long-" + platformId));
+ testdir.Create();
+ FileInfo f1 = new FileInfo(Path.Combine(testdir.FullName, "longfilename" + platformId + ".tst"));
+ using (FileStream fos = new FileStream(f1.FullName, FileMode.CreateNew, FileAccess.Write))
+ { }
+ FileInfo f2 = null, f3 = null;
+ DirectoryInfo dir2 = null;
+ try
+ {
+ String dirName1 = f1.GetCanonicalPath();
+ FileInfo f4 = new FileInfo(Path.Combine(testdir.FullName, "longfi~1.tst"));
+ /*
+ * If the "short file name" doesn't exist, then assume that the
+ * 8.3 file name compatibility is disabled.
+ */
+ if (f4.Exists)
+ {
+ String dirName2 = f4.GetCanonicalPath();
+ assertEquals("Test 6: Incorrect Path Returned.", dirName1,
+ dirName2);
+ dir2 = new DirectoryInfo(Path.Combine(testdir.FullName, "longdirectory" + platformId));
+ if (!dir2.Exists)
+ {
+ try
+ {
+ dir2.Create();
+ }
+ catch
+ {
+ }
+ finally
+ {
+ if (!Directory.Exists(dir2.FullName))
+ fail("Could not create dir: " + dir2);
+ }
+
+ }
+ f2 = new FileInfo(testdir.FullName + Path.DirectorySeparatorChar + "longdirectory"
+ + platformId + Path.DirectorySeparatorChar + "Test" + Path.DirectorySeparatorChar + dots
+ + Path.DirectorySeparatorChar + "longfilename.tst");
+ using (FileStream fos2 = new FileStream(f2.FullName, FileMode.CreateNew, FileAccess.Write))
+ { }
+ dirName1 = f2.GetCanonicalPath();
+ f3 = new FileInfo(testdir.FullName + Path.DirectorySeparatorChar + "longdi~1"
+ + Path.DirectorySeparatorChar + "Test" + Path.DirectorySeparatorChar + dots + Path.DirectorySeparatorChar
+ + "longfi~1.tst");
+ dirName2 = f3.GetCanonicalPath();
+ assertEquals("Test 7: Incorrect Path Returned.", dirName1,
+ dirName2);
+ }
+ }
+ finally
+ {
+ f1.Delete();
+ if (f2 != null)
+ {
+ f2.Delete();
+ }
+ if (dir2 != null)
+ {
+ dir2.Delete();
+ }
+ testdir.Delete();
+ }
+ }
+ }
+
+ private static String addTrailingSlash(String path)
+ {
+ if (Path.DirectorySeparatorChar == path[path.Length - 1])
+ {
+ return path;
+ }
+ return path + Path.DirectorySeparatorChar;
+ }
+
+ [Test, LuceneNetSpecific]
+ public void TestGetCanonicalPathDriveLetterNormalization()
+ {
+ bool onWindows = (Path.DirectorySeparatorChar == '\\');
+ if (onWindows)
+ {
+ var path = @"f:\testing\on\Windows";
+ var expected = @"F:\testing\on\Windows";
+
+ var dir = new DirectoryInfo(path);
+
+ assertEquals(expected, dir.GetCanonicalPath());
+ }
+ }
+
+ [Test, LuceneNetSpecific]
+ public void TestGetCanonicalPathDriveLetter()
+ {
+ bool onWindows = (Path.DirectorySeparatorChar == '\\');
+ if (onWindows)
+ {
+ var path = new FileInfo(@"c:\").GetCanonicalPath();
+ if (path.Length > 3)
+ fail("Drive letter incorrectly represented");
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8b7b9cb6/src/Lucene.Net/Support/IO/FileSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/IO/FileSupport.cs b/src/Lucene.Net/Support/IO/FileSupport.cs
index 99ac644..db64b87 100644
--- a/src/Lucene.Net/Support/IO/FileSupport.cs
+++ b/src/Lucene.Net/Support/IO/FileSupport.cs
@@ -1,5 +1,6 @@
using Lucene.Net.Util;
using System;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@@ -177,5 +178,128 @@ namespace Lucene.Net.Support.IO
return Path.Combine(directory.FullName, string.Concat(prefix, randomFileName));
}
+
+ private static readonly IDictionary<string, string> fileCanonPathCache = new Dictionary<string, string>();
+
+ /// <summary>
+ /// Returns the absolute path of this <see cref="FileSystemInfo"/> with all references resolved and
+ /// any drive letters normalized to upper case on Windows. An
+ /// <em>absolute</em> path is one that begins at the root of the file
+ /// system. The canonical path is one in which all references have been
+ /// resolved. For the cases of '..' and '.', where the file system supports
+ /// parent and working directory respectively, these are removed and replaced
+ /// with a direct directory reference.
+ /// </summary>
+ /// <param name="path">This <see cref="FileSystemInfo"/> instance.</param>
+ /// <returns>The canonical path of this file.</returns>
+ // LUCENENET NOTE: Implementation ported mostly from Apache Harmony
+ public static string GetCanonicalPath(this FileSystemInfo path)
+ {
+ string absPath = path.FullName; // LUCENENET NOTE: This internally calls GetFullPath(), which resolves relative paths
+ byte[] result = Encoding.UTF8.GetBytes(absPath);
+
+ string canonPath;
+ if (fileCanonPathCache.TryGetValue(absPath, out canonPath) && canonPath != null)
+ {
+ return canonPath;
+ }
+
+ // LUCENENET TODO: On Unix, this resolves symbolic links. Not sure
+ // if it is safe to assume Path.GetFullPath() does that for us.
+ //if (Path.DirectorySeparatorChar == '/')
+ //{
+ // //// resolve the full path first
+ // //result = resolveLink(result, result.Length, false);
+ // //// resolve the parent directories
+ // //result = resolve(result);
+ //}
+ int numSeparators = 1;
+ for (int i = 0; i < result.Length; i++)
+ {
+ if (result[i] == Path.DirectorySeparatorChar)
+ {
+ numSeparators++;
+ }
+ }
+ int[] sepLocations = new int[numSeparators];
+ int rootLoc = 0;
+ if (Path.DirectorySeparatorChar == '\\')
+ {
+ if (result[0] == '\\')
+ {
+ rootLoc = (result.Length > 1 && result[1] == '\\') ? 1 : 0;
+ }
+ else
+ {
+ rootLoc = 2; // skip drive i.e. c:
+ }
+ }
+ byte[] newResult = new byte[result.Length + 1];
+ int newLength = 0, lastSlash = 0, foundDots = 0;
+ sepLocations[lastSlash] = rootLoc;
+ for (int i = 0; i <= result.Length; i++)
+ {
+ if (i < rootLoc)
+ {
+ // Normalize case of Windows drive letter to upper
+ newResult[newLength++] = (byte)char.ToUpperInvariant((char)result[i]);
+ }
+ else
+ {
+ if (i == result.Length || result[i] == Path.DirectorySeparatorChar)
+ {
+ if (i == result.Length && foundDots == 0)
+ {
+ break;
+ }
+ if (foundDots == 1)
+ {
+ /* Don't write anything, just reset and continue */
+ foundDots = 0;
+ continue;
+ }
+ if (foundDots > 1)
+ {
+ /* Go back N levels */
+ lastSlash = lastSlash > (foundDots - 1) ? lastSlash
+ - (foundDots - 1) : 0;
+ newLength = sepLocations[lastSlash] + 1;
+ foundDots = 0;
+ continue;
+ }
+ sepLocations[++lastSlash] = newLength;
+ newResult[newLength++] = (byte)Path.DirectorySeparatorChar;
+ continue;
+ }
+ if (result[i] == '.')
+ {
+ foundDots++;
+ continue;
+ }
+ /* Found some dots within text, write them out */
+ if (foundDots > 0)
+ {
+ for (int j = 0; j < foundDots; j++)
+ {
+ newResult[newLength++] = (byte)'.';
+ }
+ }
+ newResult[newLength++] = result[i];
+ foundDots = 0;
+ }
+ }
+ // remove trailing slash
+ if (newLength > (rootLoc + 1)
+ && newResult[newLength - 1] == Path.DirectorySeparatorChar)
+ {
+ newLength--;
+ }
+ newResult[newLength] = 0;
+ //newResult = getCanonImpl(newResult);
+ newLength = newResult.Length;
+ canonPath = Encoding.UTF8.GetString(newResult, 0, newLength).TrimEnd('\0'); // LUCENENET: Eliminate null terminator char
+ fileCanonPathCache[absPath] = canonPath;
+ return canonPath;
+ }
}
}
\ No newline at end of file
[8/8] lucenenet git commit: COMPATIBILITY: Refactored NativeFSLock
since the implementation is dependent upon the HResult value,
which may be different for each OS. The previous implementation of
NativeFSLock was resurrected and is being used as a fallba
Posted by ni...@apache.org.
COMPATIBILITY: Refactored NativeFSLock since the implementation is dependent upon the HResult value, which may be different for each OS. The previous implementation of NativeFSLock was resurrected and is being used as a fallback for non-Windows platforms. The existing NativeFSLock was made abstract and renamed SharingAwareFSLock. At some point perhaps we can have other subclasses of this lock that will run on other popular platforms.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/8866a3af
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/8866a3af
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/8866a3af
Branch: refs/heads/master
Commit: 8866a3afddce54e6a3cd8fd0fbca55d6b04b4a67
Parents: b5b6179
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Sep 25 18:51:49 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Sep 25 18:51:49 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Store/NativeFSLockFactory.cs | 278 ++++++++++++++++++++---
1 file changed, 248 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8866a3af/src/Lucene.Net/Store/NativeFSLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/NativeFSLockFactory.cs b/src/Lucene.Net/Store/NativeFSLockFactory.cs
index bdf0dc4..b5b65fc 100644
--- a/src/Lucene.Net/Store/NativeFSLockFactory.cs
+++ b/src/Lucene.Net/Store/NativeFSLockFactory.cs
@@ -90,7 +90,7 @@ namespace Lucene.Net.Store
// LUCENENET: NativeFSLocks in Java are infact singletons; this is how we mimick that to track instances and make sure
// IW.Unlock and IW.IsLocked works correctly
- internal static readonly Dictionary<string, NativeFSLock> _locks = new Dictionary<string, NativeFSLock>();
+ internal static readonly Dictionary<string, Lock> _locks = new Dictionary<string, Lock>();
/// <summary>
/// Given a lock name, return the full prefixed path of the actual lock file.
@@ -109,17 +109,27 @@ namespace Lucene.Net.Store
public override Lock MakeLock(string lockName)
{
var path = GetCanonicalPathOfLockFile(lockName);
- NativeFSLock l;
+ Lock l;
lock (_locks)
if (!_locks.TryGetValue(path, out l))
- _locks.Add(path, l = new NativeFSLock(this, m_lockDir, path));
+ _locks.Add(path, l = NewLock(path));
return l;
}
+ // Internal for testing
+ internal virtual Lock NewLock(string path)
+ {
+ if (Constants.WINDOWS)
+ return new WindowsNativeFSLock(this, m_lockDir, path);
+
+ // Fallback implementation for unknown platforms that don't rely on HResult
+ return new NativeFSLock(this, m_lockDir, path);
+ }
+
public override void ClearLock(string lockName)
{
var path = GetCanonicalPathOfLockFile(lockName);
- NativeFSLock l;
+ Lock l;
// this is the reason why we can't use ConcurrentDictionary: we need the removal and disposal of the lock to be atomic
// otherwise it may clash with MakeLock making a lock and ClearLock disposing of it in another thread.
lock (_locks)
@@ -131,14 +141,24 @@ namespace Lucene.Net.Store
}
}
+
+ // LUCENENET NOTE: We use this implementation as a fallback for platforms that we don't
+ // know the HResult numbers for lock and file sharing errors.
+ //
+ // Note that using SharingAwareNativeFSLock would be ideal for all platforms. However,
+ // at the time of this writing there is no cross-platform way to identify sharing errors
+ // or lock errors because the values of HResult depend on the specific OS platform we
+ // are running on. Unfortunately, researching what these numbers may be even for Linux and
+ // OSx turned up nothing, and it is also unclear whether different flavors of Linux/Unix will have
+ // different HResult numbers. The best we can hope for is for people to contribute subclasses
+ // of SharingAwareNativeFSLock for the most popular platforms and fall back to this (substandard)
+ // implementation for all of the other platforms. See WindowsNativeFSLock for an example of what
+ // one of these subclasses should look like. The NativeFSLockFactory.NewLock() factory method
+ // is the only place where adding the platform-specific logic which class to instantiate is required.
+ //
+ // Reference: https://stackoverflow.com/q/46380483
internal class NativeFSLock : Lock
{
-#if FEATURE_FILESTREAM_LOCK
- private const int ERROR_LOCK_VIOLATION = 0x21;
-#else
- private const int ERROR_SHARE_VIOLATION = 0x20;
-#endif
-
private readonly NativeFSLockFactory outerInstance;
private FileStream channel;
@@ -152,21 +172,180 @@ namespace Lucene.Net.Store
this.path = path;
}
- /// <summary>
- /// Return true if the <see cref="IOException"/> is the result of a lock violation
- /// </summary>
- /// <param name="e"></param>
- /// <returns></returns>
- private static bool IsLockOrShareViolation(IOException e)
+ public override bool Obtain()
{
- var result = e.HResult & 0xFFFF;
-#if FEATURE_FILESTREAM_LOCK
- return result == ERROR_LOCK_VIOLATION;
-#else
- return result == ERROR_SHARE_VIOLATION;
-#endif
+ lock (this)
+ {
+ FailureReason = null;
+
+ if (channel != null)
+ {
+ // Our instance is already locked:
+ return false;
+ }
+
+ if (!System.IO.Directory.Exists(lockDir.FullName))
+ {
+ try
+ {
+ System.IO.Directory.CreateDirectory(lockDir.FullName);
+ }
+ catch
+ {
+ throw new IOException("Cannot create directory: " + lockDir.FullName);
+ }
+ }
+ else if (File.Exists(lockDir.FullName))
+ {
+ throw new IOException("Found regular file where directory expected: " + lockDir.FullName);
+ }
+
+ var success = false;
+ try
+ {
+ channel = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
+
+ success = true;
+ }
+ catch (IOException e)
+ {
+ FailureReason = e;
+ }
+ // LUCENENET: UnauthorizedAccessException does not derive from IOException like in java
+ catch (UnauthorizedAccessException e)
+ {
+ // At least on OS X, we will sometimes get an
+ // intermittent "Permission Denied" Exception,
+ // which seems to simply mean "you failed to get
+ // the lock". But other IOExceptions could be
+ // "permanent" (eg, locking is not supported via
+ // the filesystem). So, we record the failure
+ // reason here; the timeout obtain (usually the
+ // one calling us) will use this as "root cause"
+ // if it fails to get the lock.
+ FailureReason = e;
+ }
+ finally
+ {
+ if (!success)
+ {
+ IOUtils.DisposeWhileHandlingException(channel);
+ channel = null;
+ }
+ }
+
+ return channel != null;
+ }
}
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ lock (this)
+ {
+ // whether or not we have created a file, we need to remove
+ // the lock instance from the dictionary that tracks them.
+ try
+ {
+ lock (NativeFSLockFactory._locks)
+ NativeFSLockFactory._locks.Remove(path);
+ }
+ finally
+ {
+ if (channel != null)
+ {
+ IOUtils.DisposeWhileHandlingException(channel);
+ channel = null;
+
+ bool tmpBool;
+ if (File.Exists(path))
+ {
+ File.Delete(path);
+ tmpBool = true;
+ }
+ else if (System.IO.Directory.Exists(path))
+ {
+ System.IO.Directory.Delete(path);
+ tmpBool = true;
+ }
+ else
+ {
+ tmpBool = false;
+ }
+ if (!tmpBool)
+ {
+ throw new LockReleaseFailedException("failed to delete " + path);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public override bool IsLocked()
+ {
+ lock (this)
+ {
+ // The test for is isLocked is not directly possible with native file locks:
+
+ // First a shortcut, if a lock reference in this instance is available
+ if (channel != null)
+ {
+ return true;
+ }
+
+ // Look if lock file is present; if not, there can definitely be no lock!
+ bool tmpBool;
+ if (System.IO.File.Exists(path))
+ tmpBool = true;
+ else
+ tmpBool = System.IO.Directory.Exists(path);
+ if (!tmpBool)
+ return false;
+
+ // Try to obtain and release (if was locked) the lock
+ try
+ {
+ bool obtained = Obtain();
+ if (obtained)
+ {
+ Dispose();
+ }
+ return !obtained;
+ }
+ catch (IOException)
+ {
+ return false;
+ }
+ }
+ }
+
+ public override string ToString()
+ {
+ return "NativeFSLock@" + path;
+ }
+ }
+
+ // Abstract class that can be used to create additional native locks that
+ // work with OS-specific HResult values.
+ internal abstract class SharingAwareNativeFSLock : Lock
+ {
+ private readonly NativeFSLockFactory outerInstance;
+
+ private FileStream channel;
+ private readonly string path;
+ private readonly DirectoryInfo lockDir;
+
+ public SharingAwareNativeFSLock(NativeFSLockFactory outerInstance, DirectoryInfo lockDir, string path)
+ {
+ this.outerInstance = outerInstance;
+ this.lockDir = lockDir;
+ this.path = path;
+ }
+
+ protected abstract bool IsLockOrShareViolation(IOException e);
+
private FileStream GetLockFileStream(FileMode mode)
{
if (!System.IO.Directory.Exists(lockDir.FullName))
@@ -220,10 +399,15 @@ namespace Lucene.Net.Store
// LUCENENET: UnauthorizedAccessException does not derive from IOException like in java
catch (UnauthorizedAccessException e)
{
- // On Windows, we can get intermittent "Access
- // Denied" here. So, we treat this as failure to
- // acquire the lock, but, store the reason in case
- // there is in fact a real error case.
+ // At least on OS X, we will sometimes get an
+ // intermittent "Permission Denied" Exception,
+ // which seems to simply mean "you failed to get
+ // the lock". But other IOExceptions could be
+ // "permanent" (eg, locking is not supported via
+ // the filesystem). So, we record the failure
+ // reason here; the timeout obtain (usually the
+ // one calling us) will use this as "root cause"
+ // if it fails to get the lock.
FailureReason = e;
}
@@ -257,10 +441,15 @@ namespace Lucene.Net.Store
// LUCENENET: UnauthorizedAccessException does not derive from IOException like in java
catch (UnauthorizedAccessException e)
{
- // On Windows, we can get intermittent "Access
- // Denied" here. So, we treat this as failure to
- // acquire the lock, but, store the reason in case
- // there is in fact a real error case.
+ // At least on OS X, we will sometimes get an
+ // intermittent "Permission Denied" Exception,
+ // which seems to simply mean "you failed to get
+ // the lock". But other IOExceptions could be
+ // "permanent" (eg, locking is not supported via
+ // the filesystem). So, we record the failure
+ // reason here; the timeout obtain (usually the
+ // one calling us) will use this as "root cause"
+ // if it fails to get the lock.
FailureReason = e;
}
#endif
@@ -349,4 +538,33 @@ namespace Lucene.Net.Store
return "NativeFSLock@" + path;
}
}
+
+
+ // LUCENENET: Lock that uses HResult native to Windows
+ internal class WindowsNativeFSLock : SharingAwareNativeFSLock
+ {
+#if FEATURE_FILESTREAM_LOCK
+ private const int ERROR_LOCK_VIOLATION = 0x21;
+#else
+ private const int ERROR_SHARE_VIOLATION = 0x20;
+#endif
+
+ public WindowsNativeFSLock(NativeFSLockFactory outerInstance, DirectoryInfo lockDir, string path)
+ : base(outerInstance, lockDir, path)
+ {
+ }
+
+ /// <summary>
+ /// Return true if the <see cref="IOException"/> is the result of a lock violation
+ /// </summary>
+ protected override bool IsLockOrShareViolation(IOException e)
+ {
+ var result = e.HResult & 0xFFFF;
+#if FEATURE_FILESTREAM_LOCK
+ return result == ERROR_LOCK_VIOLATION;
+#else
+ return result == ERROR_SHARE_VIOLATION;
+#endif
+ }
+ }
}
\ No newline at end of file
[7/8] lucenenet git commit: BUG:
Lucene.Net.Tests.Search.TestMultiTermConstantScore: Added check to ensure a
null instance variable doesn't cause the AfterClass method to fail
Posted by ni...@apache.org.
BUG: Lucene.Net.Tests.Search.TestMultiTermConstantScore: Added check to ensure a null instance variable doesn't cause the AfterClass method to fail
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/b5b6179d
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/b5b6179d
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/b5b6179d
Branch: refs/heads/master
Commit: b5b6179d81c07c1f2dd946b7fde89f2f0f732393
Parents: f486e5c
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Sep 25 00:31:59 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Sep 25 00:31:59 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b5b6179d/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs b/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
index 55b9773..e98380b 100644
--- a/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
+++ b/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
@@ -90,8 +90,8 @@ namespace Lucene.Net.Search
[OneTimeTearDown]
public override void AfterClass()
{
- Reader.Dispose();
- Small.Dispose();
+ Reader?.Dispose();
+ Small?.Dispose();
Reader = null;
Small = null;
base.AfterClass();
[6/8] lucenenet git commit: Lucene.Net.Util.Constants: Fixed OS check
for FreeBSD and SunOS so it will work if/when those platforms become
available on .NET Standard
Posted by ni...@apache.org.
Lucene.Net.Util.Constants: Fixed OS check for FreeBSD and SunOS so it will work if/when those platforms become available on .NET Standard
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/f486e5c4
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/f486e5c4
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/f486e5c4
Branch: refs/heads/master
Commit: f486e5c421f2be952ff6805b8b0dfa457513e5a1
Parents: 5d9a9a0
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Sep 25 00:28:49 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Sep 25 00:28:49 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Util/Constants.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f486e5c4/src/Lucene.Net/Util/Constants.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Util/Constants.cs b/src/Lucene.Net/Util/Constants.cs
index 6b79fdc..ff29507 100644
--- a/src/Lucene.Net/Util/Constants.cs
+++ b/src/Lucene.Net/Util/Constants.cs
@@ -140,7 +140,8 @@ namespace Lucene.Net.Util
WINDOWS = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
LINUX = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
MAC_OS_X = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
- // LUCENENET NOTE: SunOS and FreeBSD not supported
+ FREE_BSD = RuntimeInformation.IsOSPlatform(OSPlatform.Create("FreeBSD"));
+ SUN_OS = RuntimeInformation.IsOSPlatform(OSPlatform.Create("SunOS"));
#else
// LUCENENET NOTE: On .NET Framework, our only possibilities are Windows or Linux
PlatformID pid = Environment.OSVersion.Platform;
[5/8] lucenenet git commit: SWEEP: Swapped GetCanonicalPath() call
into each of the locations where it was originally used in Lucene
Posted by ni...@apache.org.
SWEEP: Swapped GetCanonicalPath() call into each of the locations where it was originally used in Lucene
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/5d9a9a04
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/5d9a9a04
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/5d9a9a04
Branch: refs/heads/master
Commit: 5d9a9a04ceca57f38bdbf0e178b8a378eb048384
Parents: 8b7b9cb
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Sep 25 00:27:28 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Sep 25 00:27:28 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Benchmark/ByTask/Feeds/DirContentSource.cs | 3 ++-
.../ByTask/Feeds/ReutersContentSource.cs | 3 ++-
.../ByTask/Feeds/TrecContentSourceTest.cs | 3 ++-
src/Lucene.Net/Store/FSDirectory.cs | 8 ++++----
src/Lucene.Net/Store/NativeFSLockFactory.cs | 9 +++++----
5 files changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5d9a9a04/src/Lucene.Net.Benchmark/ByTask/Feeds/DirContentSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/DirContentSource.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/DirContentSource.cs
index c14d578..a939c1b 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Feeds/DirContentSource.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/DirContentSource.cs
@@ -1,5 +1,6 @@
using Lucene.Net.Benchmarks.ByTask.Utils;
using Lucene.Net.Support;
+using Lucene.Net.Support.IO;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -198,7 +199,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds
}
f = inputFiles.Current;
// System.err.println(f);
- name = f.FullName + "_" + iteration;
+ name = f.GetCanonicalPath() + "_" + iteration;
}
string line = null;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5d9a9a04/src/Lucene.Net.Benchmark/ByTask/Feeds/ReutersContentSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/ReutersContentSource.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/ReutersContentSource.cs
index c61ce2f..a98c054 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Feeds/ReutersContentSource.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/ReutersContentSource.cs
@@ -1,4 +1,5 @@
using Lucene.Net.Benchmarks.ByTask.Utils;
+using Lucene.Net.Support.IO;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -95,7 +96,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds
iteration++;
}
f = inputFiles[nextFile++];
- name = f.FullName + "_" + iteration;
+ name = f.GetCanonicalPath() + "_" + iteration;
}
using (TextReader reader = new StreamReader(new FileStream(f.FullName, FileMode.Open, FileAccess.Read), Encoding.UTF8))
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5d9a9a04/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/TrecContentSourceTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/TrecContentSourceTest.cs b/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/TrecContentSourceTest.cs
index d83bb5a..2ae8d68 100644
--- a/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/TrecContentSourceTest.cs
+++ b/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/TrecContentSourceTest.cs
@@ -1,5 +1,6 @@
using Lucene.Net.Benchmarks.ByTask.Utils;
using Lucene.Net.Documents;
+using Lucene.Net.Support.IO;
using Lucene.Net.Util;
using NUnit.Framework;
using System;
@@ -374,7 +375,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds
props["content.source.verbose"] = "false";
props["content.source.excludeIteration"] = "true";
props["doc.maker.forever"] = "false";
- props["docs.dir"] = dataDir.FullName.Replace('\\', '/');
+ props["docs.dir"] = dataDir.GetCanonicalPath().Replace('\\', '/');
props["trec.doc.parser"] = typeof(TrecParserByPath).AssemblyQualifiedName;
props["content.source.forever"] = "false";
tcs.SetConfig(new Config(props));
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5d9a9a04/src/Lucene.Net/Store/FSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs
index 4c408ae..6cc3caf 100644
--- a/src/Lucene.Net/Store/FSDirectory.cs
+++ b/src/Lucene.Net/Store/FSDirectory.cs
@@ -1,9 +1,9 @@
+using Lucene.Net.Support.IO;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;// Used only for WRITE_LOCK_NAME in deprecated create=true case:
-using Lucene.Net.Support;
namespace Lucene.Net.Store
{
@@ -118,7 +118,7 @@ namespace Lucene.Net.Store
{
lockFactory = new NativeFSLockFactory();
}
- m_directory = path; // Lucene.NET doesn't need to call GetCanonicalPath since we already have DirectoryInfo handy
+ m_directory = new DirectoryInfo(path.GetCanonicalPath());
if (File.Exists(path.FullName))
{
@@ -215,7 +215,7 @@ namespace Lucene.Net.Store
lf.SetLockDir(m_directory);
lf.LockPrefix = null;
}
- else if (dir.FullName.Equals(m_directory.FullName, StringComparison.Ordinal))
+ else if (dir.GetCanonicalPath().Equals(m_directory.GetCanonicalPath(), StringComparison.Ordinal))
{
lf.LockPrefix = null;
}
@@ -395,7 +395,7 @@ namespace Lucene.Net.Store
string dirName; // name to be hashed
try
{
- dirName = m_directory.FullName;
+ dirName = m_directory.GetCanonicalPath();
}
catch (IOException e)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5d9a9a04/src/Lucene.Net/Store/NativeFSLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/NativeFSLockFactory.cs b/src/Lucene.Net/Store/NativeFSLockFactory.cs
index ca2a158..bdf0dc4 100644
--- a/src/Lucene.Net/Store/NativeFSLockFactory.cs
+++ b/src/Lucene.Net/Store/NativeFSLockFactory.cs
@@ -1,3 +1,4 @@
+using Lucene.Net.Support.IO;
using Lucene.Net.Util;
using System;
using System.IO;
@@ -96,18 +97,18 @@ namespace Lucene.Net.Store
/// </summary>
/// <param name="lockName"></param>
/// <returns></returns>
- private string GetPathOfLockFile(string lockName)
+ private string GetCanonicalPathOfLockFile(string lockName)
{
if (m_lockPrefix != null)
{
lockName = m_lockPrefix + "-" + lockName;
}
- return Path.Combine(m_lockDir.FullName, lockName);
+ return new FileInfo(Path.Combine(m_lockDir.FullName, lockName)).GetCanonicalPath();
}
public override Lock MakeLock(string lockName)
{
- var path = GetPathOfLockFile(lockName);
+ var path = GetCanonicalPathOfLockFile(lockName);
NativeFSLock l;
lock (_locks)
if (!_locks.TryGetValue(path, out l))
@@ -117,7 +118,7 @@ namespace Lucene.Net.Store
public override void ClearLock(string lockName)
{
- var path = GetPathOfLockFile(lockName);
+ var path = GetCanonicalPathOfLockFile(lockName);
NativeFSLock l;
// this is the reason why we can't use ConcurrentDictionary: we need the removal and disposal of the lock to be atomic
// otherwise it may clash with MakeLock making a lock and ClearLock disposing of it in another thread.