This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 216110
Collapse All | Expand All

(-)masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObj.java (-7 / +30 lines)
Lines 62-67 Link Here
62
import org.netbeans.modules.masterfs.filebasedfs.utils.FileInfo;
62
import org.netbeans.modules.masterfs.filebasedfs.utils.FileInfo;
63
import org.netbeans.modules.masterfs.filebasedfs.utils.Utils;
63
import org.netbeans.modules.masterfs.filebasedfs.utils.Utils;
64
import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
64
import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
65
import org.openide.filesystems.FileAlreadyLockedException;
65
import org.openide.filesystems.FileLock;
66
import org.openide.filesystems.FileLock;
66
import org.openide.filesystems.FileObject;
67
import org.openide.filesystems.FileObject;
67
import org.openide.util.Enumerations;
68
import org.openide.util.Enumerations;
Lines 348-367 Link Here
348
        return Enumerations.empty();
349
        return Enumerations.empty();
349
    }
350
    }
350
351
351
352
    @Override
352
    @Override
353
    public boolean isLocked() {
354
        FileLock fLock = null;
355
        try {
356
            fLock = lockImpl(false);
357
        } catch (FileAlreadyLockedException fax) {
358
            return true;
359
        } catch (IOException ex) {
360
            return false;
361
        } finally {
362
            if (fLock != null) {
363
                fLock.releaseLock();
364
            }
365
        }
366
        return fLock == null;
367
    }
368
    
369
    @Override
353
    public final FileLock lock() throws IOException {
370
    public final FileLock lock() throws IOException {
371
        return lockImpl(true);
372
    }
373
374
    private FileLock lockImpl(boolean notifyExtension) throws IOException {
354
        final File me = getFileName().getFile();
375
        final File me = getFileName().getFile();
355
        if (!getProvidedExtensions().canWrite(me)) {
376
        if (!getProvidedExtensions().canWrite(me)) {
356
            FSException.io("EXC_CannotLock", me);
377
            FSException.io("EXC_CannotLock", me);
357
        }
378
        }
358
        try {            
379
        try {            
359
            LockForFile result = LockForFile.tryLock(me);
380
            LockForFile result = LockForFile.tryLock(me);
360
            try {
381
            if(notifyExtension) {
361
                getProvidedExtensions().fileLocked(this);
382
                try {
362
            } catch (IOException ex) {
383
                    getProvidedExtensions().fileLocked(this);
363
                result.releaseLock(false);
384
                } catch (IOException ex) {
364
                throw ex;
385
                    result.releaseLock(false);
386
                    throw ex;
387
                }
365
            }
388
            }
366
            return result;
389
            return result;
367
        } catch (FileNotFoundException ex) {
390
        } catch (FileNotFoundException ex) {
Lines 381-387 Link Here
381
            throw fex;
404
            throw fex;
382
        }
405
        }
383
    }
406
    }
384
407
    
385
    final boolean checkLock(final FileLock lock) throws IOException {
408
    final boolean checkLock(final FileLock lock) throws IOException {
386
        final File f = getFileName().getFile();
409
        final File f = getFileName().getFile();
387
        return ((lock instanceof LockForFile) && Utils.equals(((LockForFile) lock).getFile(), f));
410
        return ((lock instanceof LockForFile) && Utils.equals(((LockForFile) lock).getFile(), f));

Return to bug 216110