20 namespace Lucene.Net.Store
78 : this(new System.IO.DirectoryInfo(lockDirName))
82 public override Lock MakeLock(System.String lockName)
84 if (internalLockPrefix != null)
86 lockName = internalLockPrefix +
"-" + lockName;
91 public override void ClearLock(System.String lockName)
94 if (System.IO.File.Exists(internalLockDir.FullName))
97 tmpBool = System.IO.Directory.Exists(internalLockDir.FullName);
100 if (internalLockPrefix != null)
102 lockName = internalLockPrefix +
"-" + lockName;
104 System.IO.FileInfo lockFile =
new System.IO.FileInfo(System.IO.Path.Combine(internalLockDir.FullName, lockName));
106 if (System.IO.File.Exists(lockFile.FullName))
109 tmpBool2 = System.IO.Directory.Exists(lockFile.FullName);
111 if (System.IO.File.Exists(lockFile.FullName))
113 System.IO.File.Delete(lockFile.FullName);
116 else if (System.IO.Directory.Exists(lockFile.FullName))
118 System.IO.Directory.Delete(lockFile.FullName);
123 if (tmpBool2 && !tmpBool3)
125 throw new System.IO.IOException(
"Cannot delete " + lockFile);
135 internal System.IO.FileInfo lockFile;
136 internal System.IO.DirectoryInfo lockDir;
138 [System.Obsolete(
"Use the constructor that takes a DirectoryInfo, this will be removed in the 3.0 release")]
139 public SimpleFSLock(System.IO.FileInfo lockDir, System.String lockFileName) : this(new System.IO.DirectoryInfo(lockDir.FullName), lockFileName)
143 public SimpleFSLock(System.IO.DirectoryInfo lockDir, System.String lockFileName)
145 this.lockDir =
new System.IO.DirectoryInfo(lockDir.FullName);
146 lockFile =
new System.IO.FileInfo(System.IO.Path.Combine(lockDir.FullName, lockFileName));
149 public override bool Obtain()
154 if (System.IO.File.Exists(lockDir.FullName))
157 tmpBool = System.IO.Directory.Exists(lockDir.FullName);
162 System.IO.Directory.CreateDirectory(lockDir.FullName);
166 throw new System.IO.IOException(
"Cannot create directory: " + lockDir.FullName);
173 System.IO.Directory.Exists(lockDir.FullName);
177 throw new System.IO.IOException(
"Found regular file where directory expected: " + lockDir.FullName);
187 System.IO.FileStream createdFile = lockFile.Create();
193 public override void Release()
196 if (System.IO.File.Exists(lockFile.FullName))
199 tmpBool = System.IO.Directory.Exists(lockFile.FullName);
201 if (System.IO.File.Exists(lockFile.FullName))
203 System.IO.File.Delete(lockFile.FullName);
206 else if (System.IO.Directory.Exists(lockFile.FullName))
208 System.IO.Directory.Delete(lockFile.FullName);
213 if (tmpBool && !tmpBool2)
217 public override bool IsLocked()
220 if (System.IO.File.Exists(lockFile.FullName))
223 tmpBool = System.IO.Directory.Exists(lockFile.FullName);
227 public override System.String ToString()
229 return "SimpleFSLock@" + lockFile;