// permit subclassing private void Init(System.IO.FileInfo 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; bool doClearLockID = false; if (lockFactory == null) { if (disableLocks) { // Locks are disabled: lockFactory = NoLockFactory.GetNoLockFactory(); } else { // Our default lock is SimpleFSLockFactory; // default lockDir is our index directory: lockFactory = new SimpleFSLockFactory(path); doClearLockID = true; } } SetLockFactory(lockFactory); if (doClearLockID) { // Clear the prefix because write.lock will be // stored in our directory: lockFactory.SetLockPrefix(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); } } }
/* 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); } } }
// permit subclassing private void Init(System.IO.FileInfo 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; bool doClearLockID = false; 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) { throw new System.IO.IOException("unable to find LockClass " + lockClassName); } try { lockFactory = (LockFactory)System.Activator.CreateInstance(c, true); } catch (System.UnauthorizedAccessException) { throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName); } catch (System.InvalidCastException) { throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory"); } catch (System.Exception ex) { throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName + "\nDetails:" + ex.Message); } if (lockFactory is NativeFSLockFactory) { ((NativeFSLockFactory)lockFactory).SetLockDir(path); } else if (lockFactory is SimpleFSLockFactory) { ((SimpleFSLockFactory)lockFactory).SetLockDir(path); } } else { // Our default lock is SimpleFSLockFactory; // default lockDir is our index directory: lockFactory = new SimpleFSLockFactory(path); doClearLockID = true; } } } SetLockFactory(lockFactory); if (doClearLockID) { // Clear the prefix because write.lock will be // stored in our directory: lockFactory.SetLockPrefix(null); } }
// permit subclassing private void Init(System.IO.FileInfo 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; bool doClearLockID = false; 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) { throw new System.IO.IOException("unable to find LockClass " + lockClassName); } try { lockFactory = (LockFactory) System.Activator.CreateInstance(c, true); } catch (System.UnauthorizedAccessException) { throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName); } catch (System.InvalidCastException) { throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory"); } catch (System.Exception ex) { throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName + "\nDetails:" + ex.Message); } if (lockFactory is NativeFSLockFactory) { ((NativeFSLockFactory) lockFactory).SetLockDir(path); } else if (lockFactory is SimpleFSLockFactory) { ((SimpleFSLockFactory) lockFactory).SetLockDir(path); } } else { // Our default lock is SimpleFSLockFactory; // default lockDir is our index directory: lockFactory = new SimpleFSLockFactory(path); doClearLockID = true; } } } SetLockFactory(lockFactory); if (doClearLockID) { // Clear the prefix because write.lock will be // stored in our directory: lockFactory.SetLockPrefix(null); } }