Lines 57-62
Link Here
|
57 |
import java.util.logging.Logger; |
57 |
import java.util.logging.Logger; |
58 |
import org.openide.filesystems.FileObject; |
58 |
import org.openide.filesystems.FileObject; |
59 |
import org.openide.filesystems.FileSystem; |
59 |
import org.openide.filesystems.FileSystem; |
|
|
60 |
import org.openide.filesystems.FileSystem.AtomicAction; |
60 |
import org.openide.filesystems.FileUtil; |
61 |
import org.openide.filesystems.FileUtil; |
61 |
import org.openide.filesystems.URLMapper; |
62 |
import org.openide.filesystems.URLMapper; |
62 |
import org.openide.modules.Places; |
63 |
import org.openide.modules.Places; |
Lines 156-187
Link Here
|
156 |
final FileObject [] dataFolder = new FileObject[] { null }; |
157 |
final FileObject [] dataFolder = new FileObject[] { null }; |
157 |
|
158 |
|
158 |
// #170182 - preventing filesystem events being fired from under the CacheFolder.class lock |
159 |
// #170182 - preventing filesystem events being fired from under the CacheFolder.class lock |
159 |
_cacheFolder.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { |
160 |
_cacheFolder.getFileSystem().runAtomicAction(new AsyncRefreshAtomicActionImpl(_cacheFolder, root, onlyIfAlreadyExists, dataFolder)); |
160 |
public void run() throws IOException { |
|
|
161 |
synchronized (CacheFolder.class) { |
162 |
loadSegments(_cacheFolder); |
163 |
final String rootName = root.toExternalForm(); |
164 |
String slice = invertedSegments.get (rootName); |
165 |
if ( slice == null) { |
166 |
if (onlyIfAlreadyExists) { |
167 |
return; |
168 |
} |
169 |
slice = SLICE_PREFIX + (++index); |
170 |
while (segments.getProperty(slice) != null) { |
171 |
slice = SLICE_PREFIX + (++index); |
172 |
} |
173 |
segments.put (slice,rootName); |
174 |
invertedSegments.put(rootName, slice); |
175 |
storeSegments(_cacheFolder); |
176 |
} |
177 |
if (onlyIfAlreadyExists) { |
178 |
dataFolder[0] = _cacheFolder.getFileObject(slice); |
179 |
} else { |
180 |
dataFolder[0] = FileUtil.createFolder(_cacheFolder, slice); |
181 |
} |
182 |
} |
183 |
} |
184 |
}); |
185 |
|
161 |
|
186 |
return dataFolder[0]; |
162 |
return dataFolder[0]; |
187 |
} |
163 |
} |
Lines 243-246
Link Here
|
243 |
private CacheFolder() { |
219 |
private CacheFolder() { |
244 |
// no-op |
220 |
// no-op |
245 |
} |
221 |
} |
|
|
222 |
|
223 |
private static class AsyncRefreshAtomicActionImpl implements AtomicAction { |
224 |
|
225 |
private final FileObject _cacheFolder; |
226 |
private final URL root; |
227 |
private final boolean onlyIfAlreadyExists; |
228 |
private final FileObject[] dataFolder; |
229 |
|
230 |
public AsyncRefreshAtomicActionImpl(FileObject _cacheFolder, URL root, boolean onlyIfAlreadyExists, FileObject[] dataFolder) { |
231 |
this._cacheFolder = _cacheFolder; |
232 |
this.root = root; |
233 |
this.onlyIfAlreadyExists = onlyIfAlreadyExists; |
234 |
this.dataFolder = dataFolder; |
235 |
} |
236 |
|
237 |
public void run() throws IOException { |
238 |
synchronized (CacheFolder.class) { |
239 |
loadSegments(_cacheFolder); |
240 |
final String rootName = root.toExternalForm(); |
241 |
String slice = invertedSegments.get (rootName); |
242 |
if ( slice == null) { |
243 |
if (onlyIfAlreadyExists) { |
244 |
return; |
245 |
} |
246 |
slice = SLICE_PREFIX + (++index); |
247 |
while (segments.getProperty(slice) != null) { |
248 |
slice = SLICE_PREFIX + (++index); |
249 |
} |
250 |
segments.put (slice,rootName); |
251 |
invertedSegments.put(rootName, slice); |
252 |
storeSegments(_cacheFolder); |
253 |
} |
254 |
if (onlyIfAlreadyExists) { |
255 |
dataFolder[0] = _cacheFolder.getFileObject(slice); |
256 |
} else { |
257 |
dataFolder[0] = FileUtil.createFolder(_cacheFolder, slice); |
258 |
} |
259 |
} |
260 |
} |
261 |
} |
246 |
} |
262 |
} |