public override void SetLockFactory(LockFactory lockFactory) { base.SetLockFactory(lockFactory); // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed // in index dir. If no index dir is given, set ourselves if (lockFactory is FSLockFactory) { FSLockFactory lf = (FSLockFactory)lockFactory; DirectoryInfo dir = lf.LockDir; // if the lock factory has no lockDir set, use the this directory as lockDir if (dir == null) { lf.SetLockDir(m_directory); lf.LockPrefix = null; } else if (dir.FullName.Equals(m_directory.FullName, StringComparison.Ordinal)) { lf.LockPrefix = null; } } }
/// <summary>Create a new FSDirectory for the named location (ctor for subclasses).</summary> /// <param name="path">the path of the directory /// </param> /// <param name="lockFactory">the lock factory to use, or null for the default /// (<see cref="NativeFSLockFactory" />); /// </param> /// <throws> IOException </throws> protected internal FSDirectory(System.IO.DirectoryInfo path, LockFactory lockFactory) { // new ctors use always NativeFSLockFactory as default: if (lockFactory == null) { lockFactory = new NativeFSLockFactory(); } // Set up lockFactory with cascaded defaults: if an instance was passed in, // use that; else if locks are disabled, use NoLockFactory; else if the // system property Lucene.Net.Store.FSDirectoryLockFactoryClass is set, // instantiate that; else, use SimpleFSLockFactory: internalDirectory = path; // due to differences in how Java & .NET refer to files, the checks are a bit different if (!internalDirectory.Exists && System.IO.File.Exists(internalDirectory.FullName)) { throw new NoSuchDirectoryException("file '" + internalDirectory.FullName + "' exists but is not a directory"); } SetLockFactory(lockFactory); // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed // in index dir. If no index dir is given, set ourselves if (lockFactory is FSLockFactory) { FSLockFactory lf = (FSLockFactory)lockFactory; System.IO.DirectoryInfo dir = lf.LockDir; // if the lock factory has no lockDir set, use the this directory as lockDir if (dir == null) { lf.LockDir = this.internalDirectory; lf.LockPrefix = null; } else if (dir.FullName.Equals(this.internalDirectory.FullName)) { lf.LockPrefix = null; } } }
/* will move to ctor, when reflection is removed in 3.0 */ private void Init(System.IO.DirectoryInfo path, LockFactory lockFactory) { // Set up lockFactory with cascaded defaults: if an instance was passed in, // use that; else if locks are disabled, use NoLockFactory; else if the // system property Lucene.Net.Store.FSDirectoryLockFactoryClass is set, // instantiate that; else, use SimpleFSLockFactory: directory = path; // due to differences in how Java & .NET refer to files, the checks are a bit different if (!directory.Exists && System.IO.File.Exists(directory.FullName)) { throw new NoSuchDirectoryException("file '" + directory.FullName + "' exists but is not a directory"); } if (lockFactory == null) { if (disableLocks) { // Locks are disabled: lockFactory = NoLockFactory.GetNoLockFactory(); } else { System.String lockClassName = SupportClass.AppSettings.Get("Lucene.Net.Store.FSDirectoryLockFactoryClass", ""); if (lockClassName != null && !lockClassName.Equals("")) { System.Type c; try { c = System.Type.GetType(lockClassName); } catch (System.Exception e) { throw new System.IO.IOException("unable to find LockClass " + lockClassName); } try { lockFactory = (LockFactory)System.Activator.CreateInstance(c, true); } catch (System.UnauthorizedAccessException e) { throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName); } catch (System.InvalidCastException e) { throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory"); } catch (System.Exception e) { throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName); } } else { // Our default lock is SimpleFSLockFactory; // default lockDir is our index directory: lockFactory = new SimpleFSLockFactory(); } } } SetLockFactory(lockFactory); // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed // in index dir. If no index dir is given, set ourselves if (lockFactory is FSLockFactory) { FSLockFactory lf = (FSLockFactory)lockFactory; System.IO.DirectoryInfo dir = lf.GetLockDir(); // if the lock factory has no lockDir set, use the this directory as lockDir if (dir == null) { lf.SetLockDir(this.directory); lf.SetLockPrefix(null); } else if (dir.FullName.Equals(this.directory.FullName)) { lf.SetLockPrefix(null); } } }