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 81510
Collapse All | Expand All

(-)apichanges.xml (+18 lines)
Lines 42-47 Link Here
42
            <class package="org.netbeans.modules.masterfs.providers" name="ProvidedExtensions"/>
42
            <class package="org.netbeans.modules.masterfs.providers" name="ProvidedExtensions"/>
43
            <issue number="73042"/>
43
            <issue number="73042"/>
44
        </change>
44
        </change>
45
        <change id="added-support-for-subversion-delete">
46
            <api name="masterfs"/>
47
            <summary><code>ProvidedExtensions.getDeleteHandler</code> was added.</summary>
48
            <version major="1" minor="10"/>
49
            <date day="01" month="08" year="2006"/>
50
            <author login="rmatous"/>
51
            <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
52
            <description>
53
                <p>
54
                    <code>ProvidedExtensions.getDeleteHandler</code> was added, which
55
                    is the way how to impose handlers for 
56
                    deleting into mastersfs implementation 
57
                    which was required by module org.netbeans.modules.subversion.
58
                </p>
59
            </description>
60
            <class package="org.netbeans.modules.masterfs.providers" name="ProvidedExtensions"/>
61
            <issue number="81510"/>
62
        </change>        
45
    </changes>
63
    </changes>
46
    <htmlcontents>
64
    <htmlcontents>
47
        <head>
65
        <head>
(-)manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.masterfs/1
2
OpenIDE-Module: org.netbeans.modules.masterfs/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/masterfs/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/masterfs/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.9
4
OpenIDE-Module-Specification-Version: 1.10
5
5
(-)src/org/netbeans/modules/masterfs/MasterFileObject.java (-14 / +41 lines)
Lines 23-28 Link Here
23
import java.io.File;
23
import java.io.File;
24
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
24
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
25
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.BaseFileObj;
25
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.BaseFileObj;
26
import org.netbeans.modules.masterfs.filebasedfs.naming.FileNaming;
27
28
import org.openide.ErrorManager;
26
import org.openide.filesystems.*;
29
import org.openide.filesystems.*;
27
import org.openide.util.Utilities;
30
import org.openide.util.Utilities;
28
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.ReplaceForSerialization;
31
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.ReplaceForSerialization;
Lines 85-91 Link Here
85
    public boolean isValid() {
88
    public boolean isValid() {
86
        FileObject deleg = getValidOrInvalid(getDelegate().getPrefered());
89
        FileObject deleg = getValidOrInvalid(getDelegate().getPrefered());
87
        File f = (deleg.isVirtual()) ? null: getResource().getFile();                
90
        File f = (deleg.isVirtual()) ? null: getResource().getFile();                
88
        return (f != null) ?  (deleg.isValid() && f.exists()) : deleg.isValid();
91
        return (f != null) ?  (deleg.isValid() && (f.exists())) : deleg.isValid();
89
    }
92
    }
90
93
91
    /**
94
    /**
Lines 293-305 Link Here
293
                }
296
                }
294
                if (canRefresh) {
297
                if (canRefresh) {
295
                    if (f != null && f.exists()) {
298
                    if (f != null && f.exists()) {
296
                        this.refresh();
299
                        if (getDeleteHandler(f) == null) {
297
                        if (deleg instanceof BaseFileObj) {//#54856
300
                            this.refresh();
298
                            FileObject child = deleg.getFileObject(name, ext);
301
                            if (deleg instanceof BaseFileObj) {//#54856
299
                            retVal = (child != null) ? transformChild(child) : null;                
302
                                FileObject child = deleg.getFileObject(name, ext);
300
                        } else {
303
                                retVal = (child != null) ? transformChild(child) : null;                
301
                            retVal = getCache().getOrCreate(childResourcePath);            
304
                            } else {
302
                        }                        
305
                                retVal = getCache().getOrCreate(childResourcePath);            
306
                            }                        
307
                        }
303
                    }
308
                    }
304
                }
309
                }
305
            }
310
            }
Lines 572-578 Link Here
572
            finishCriticalSection();
577
            finishCriticalSection();
573
        }
578
        }
574
    }
579
    }
575
580
    
576
    private ProvidedExtensions.IOHandler getRenameHandler(final String name, final String ext) {
581
    private ProvidedExtensions.IOHandler getRenameHandler(final String name, final String ext) {
577
        ProvidedExtensions pe;
582
        ProvidedExtensions pe;
578
        pe = ((MasterFileSystem.StatusImpl)MasterFileSystem.getDefault().getStatus()).getExtensions();
583
        pe = ((MasterFileSystem.StatusImpl)MasterFileSystem.getDefault().getStatus()).getExtensions();
Lines 894-902 Link Here
894
            FileEvent fe2Fire = new FileEvent(MasterFileObject.this, eventFile, fe.isExpected());
899
            FileEvent fe2Fire = new FileEvent(MasterFileObject.this, eventFile, fe.isExpected());
895
            FileObject eventFileDelegate = eventFile.getDelegate().get();
900
            FileObject eventFileDelegate = eventFile.getDelegate().get();
896
            FileObject meDelegate = MasterFileObject.this.getDelegate().get();
901
            FileObject meDelegate = MasterFileObject.this.getDelegate().get();
897
            
902
            if (fe.getFile() instanceof BaseFileObj && eventFileDelegate instanceof BaseFileObj 
898
            if (eventFileDelegate == fe.getFile() && meDelegate == fe.getSource()) {                        
903
                    && fe.getSource() instanceof BaseFileObj && meDelegate instanceof BaseFileObj) {
899
                fireFileDeletedEvent(getEnumOfListeners(), fe2Fire);
904
                FileNaming fName = ((BaseFileObj)fe.getFile()).getFileName();
905
                FileNaming sName = ((BaseFileObj)fe.getSource()).getFileName();                
906
                FileNaming f1Name = ((BaseFileObj)eventFileDelegate).getFileName();
907
                FileNaming s1Name = ((BaseFileObj)meDelegate).getFileName();
908
                if (fName.equals(f1Name) && sName.equals(s1Name)) {
909
                    fireFileDeletedEvent(getEnumOfListeners(), fe2Fire);
910
                }                
911
            } else {
912
                if (eventFileDelegate == fe.getFile() && meDelegate == fe.getSource()) {
913
                    fireFileDeletedEvent(getEnumOfListeners(), fe2Fire);
914
                }
900
            }
915
            }
901
        }
916
        }
902
917
Lines 947-952 Link Here
947
        }
962
        }
948
    }
963
    }
949
964
965
    private static ProvidedExtensions.DeleteHandler getDeleteHandler(File f) {
966
        ProvidedExtensions pe;
967
        pe = ((MasterFileSystem.StatusImpl)MasterFileSystem.getDefault().getStatus()).getExtensions();
968
        
969
        return pe.getDeleteHandler(f);
970
    }
971
    
950
    private static final class AtomicAction implements FileSystem.AtomicAction {
972
    private static final class AtomicAction implements FileSystem.AtomicAction {
951
        private int operation;
973
        private int operation;
952
        private final MasterFileObject hfoI;
974
        private final MasterFileObject hfoI;
Lines 1110-1116 Link Here
1110
        private void delete() throws IOException {
1132
        private void delete() throws IOException {
1111
            FileObject deleg = getValidOrInvalid(hfoI.getDelegate().get(), hfoI);
1133
            FileObject deleg = getValidOrInvalid(hfoI.getDelegate().get(), hfoI);
1112
            FileLock lck = Delegate.getLockForDelegate(fLockI, deleg);
1134
            FileLock lck = Delegate.getLockForDelegate(fLockI, deleg);
1113
            deleg.delete(lck);
1135
            if (deleg instanceof BaseFileObj) {
1136
                ((BaseFileObj)deleg).delete(lck, 
1137
                        MasterFileObject.getDeleteHandler(((BaseFileObj)deleg).getFileName().getFile()));
1138
            } else {
1139
                deleg.delete(lck);
1140
            }
1114
        }
1141
        }
1115
1142
1116
        private void move() throws IOException {
1143
        private void move() throws IOException {
Lines 1141-1147 Link Here
1141
                retVal = hfoI.superMove(fLockI, targetI, nameI, extI);
1168
                retVal = hfoI.superMove(fLockI, targetI, nameI, extI);
1142
            }
1169
            }
1143
        }
1170
        }
1144
1171
        
1145
        private ProvidedExtensions.IOHandler getMoveHandler() {
1172
        private ProvidedExtensions.IOHandler getMoveHandler() {
1146
            ProvidedExtensions pe;
1173
            ProvidedExtensions pe;
1147
            pe = ((MasterFileSystem.StatusImpl)MasterFileSystem.getDefault().getStatus()).getExtensions();
1174
            pe = ((MasterFileSystem.StatusImpl)MasterFileSystem.getDefault().getStatus()).getExtensions();
(-)src/org/netbeans/modules/masterfs/ProvidedExtensionsProxy.java (-1 / +13 lines)
Lines 41-46 Link Here
41
        this.annotationProviders = annotationProviders;
41
        this.annotationProviders = annotationProviders;
42
    }
42
    }
43
    
43
    
44
    public ProvidedExtensions.DeleteHandler getDeleteHandler(final File f) {
45
        ProvidedExtensions.DeleteHandler retValue = null;
46
        for (Iterator it = annotationProviders.iterator(); it.hasNext() && retValue == null;) {
47
            AnnotationProvider provider = (AnnotationProvider) it.next();
48
            final InterceptionListener iListener = (provider != null) ?  provider.getInterceptionListener() : null;
49
            if (iListener instanceof ProvidedExtensions) {
50
                retValue = ((ProvidedExtensions)iListener).getDeleteHandler(f);
51
            } 
52
        }
53
        return retValue;                        
54
    }
55
    
44
    public ProvidedExtensions.IOHandler getRenameHandler(final File from, final String newName) {
56
    public ProvidedExtensions.IOHandler getRenameHandler(final File from, final String newName) {
45
        final File to = new File(from.getParentFile(), newName);
57
        final File to = new File(from.getParentFile(), newName);
46
        IOHandler retValue = null;
58
        IOHandler retValue = null;
Lines 124-128 Link Here
124
                iListener.beforeDelete(fo);
136
                iListener.beforeDelete(fo);
125
            }
137
            }
126
        }
138
        }
127
    }        
139
    }            
128
}
140
}
(-)src/org/netbeans/modules/masterfs/filebasedfs/children/ChildrenCache.java (+8 lines)
Lines 32-37 Link Here
32
    Set getChildren(boolean rescan);
32
    Set getChildren(boolean rescan);
33
33
34
    FileNaming getChild(String childName, boolean rescan);
34
    FileNaming getChild(String childName, boolean rescan);
35
    
36
    /**
37
     * Added because of subversion support, please do don't use 
38
     * this method and use rather FileNaming getChild(String childName, boolean rescan)
39
     * This method is just good for keeping cache in state that doesn't correspond 
40
     * with disk status.
41
     */
42
    void removeChild(String childName);
35
43
36
    boolean existsInCache(String childName);
44
    boolean existsInCache(String childName);
37
45
(-)src/org/netbeans/modules/masterfs/filebasedfs/children/ChildrenSupport.java (+7 lines)
Lines 94-99 Link Here
94
        return lookupChildInCache(folder, childName) != null;
94
        return lookupChildInCache(folder, childName) != null;
95
    }
95
    }
96
    
96
    
97
    public void removeChild(final FileNaming folderName, final String childName) {
98
        FileName fName = lookupChildInCache(folderName, childName);
99
        if (fName != null) {
100
            getChildrenCache().remove(fName);
101
        }
102
    }
103
    
97
    private FileName lookupChildInCache(final FileNaming folder, final String childName) {
104
    private FileName lookupChildInCache(final FileNaming folder, final String childName) {
98
        final File f = new File(folder.getFile(), childName);
105
        final File f = new File(folder.getFile(), childName);
99
        final Integer id = NamingFactory.createID(f);
106
        final Integer id = NamingFactory.createID(f);
(-)src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/BaseFileObj.java (-6 / +38 lines)
Lines 19-24 Link Here
19
19
20
package org.netbeans.modules.masterfs.filebasedfs.fileobjects;
20
package org.netbeans.modules.masterfs.filebasedfs.fileobjects;
21
21
22
import java.util.Iterator;
22
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
23
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
23
import org.netbeans.modules.masterfs.filebasedfs.Statistics;
24
import org.netbeans.modules.masterfs.filebasedfs.Statistics;
24
import org.netbeans.modules.masterfs.filebasedfs.children.ChildrenCache;
25
import org.netbeans.modules.masterfs.filebasedfs.children.ChildrenCache;
Lines 33-40 Link Here
33
34
34
import javax.swing.event.EventListenerList;
35
import javax.swing.event.EventListenerList;
35
import java.io.*;
36
import java.io.*;
37
import java.util.ArrayList;
38
import java.util.Arrays;
36
import java.util.Date;
39
import java.util.Date;
37
import java.util.Enumeration;
40
import java.util.Enumeration;
41
import java.util.List;
38
import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
42
import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
39
import org.openide.util.Enumerations;
43
import org.openide.util.Enumerations;
40
44
Lines 154-168 Link Here
154
        final String originalExt = getExt();
158
        final String originalExt = getExt();
155
        
159
        
156
        //TODO: no lock used
160
        //TODO: no lock used
157
        if (!NamingFactory.rename(getFileName(),file2Rename.getName(),handler)) {
161
        FileNaming[] allRenamed = NamingFactory.rename(getFileName(),file2Rename.getName(),handler);
162
        if (allRenamed == null) {
158
            FileObject parentFo = getExistingParent();
163
            FileObject parentFo = getExistingParent();
159
            String parentPath = (parentFo != null) ? parentFo.getPath() : file.getParentFile().getAbsolutePath();
164
            String parentPath = (parentFo != null) ? parentFo.getPath() : file.getParentFile().getAbsolutePath();
160
            FSException.io("EXC_CannotRename", file.getName(), parentPath, file2Rename.getName());// NOI18N            
165
            FSException.io("EXC_CannotRename", file.getName(), parentPath, file2Rename.getName());// NOI18N            
161
        }
166
        }
162
163
        FileBasedFileSystem fs = getLocalFileSystem();
167
        FileBasedFileSystem fs = getLocalFileSystem();
164
        fs.getFactory().rename(); 
168
        fs.getFactory().rename(); 
165
        BaseFileObj.attribs.renameAttributes(file.getAbsolutePath().replace('\\', '/'), file2Rename.getAbsolutePath().replace('\\', '/'));//NOI18N
169
        BaseFileObj.attribs.renameAttributes(file.getAbsolutePath().replace('\\', '/'), file2Rename.getAbsolutePath().replace('\\', '/'));//NOI18N
170
        for (int i = 0; i < allRenamed.length; i++) {
171
            FolderObj par = (allRenamed[i].getParent() != null) ? 
172
                (FolderObj)fs.getFactory().get(allRenamed[i].getParent().getFile()) : null;
173
            if (par != null) {
174
                ChildrenCache childrenCache = par.getChildrenCache();
175
                final Mutex.Privileged mutexPrivileged = (childrenCache != null) ? childrenCache.getMutexPrivileged() : null;
176
                if (mutexPrivileged != null) mutexPrivileged.enterWriteAccess();
177
                try {
178
                    childrenCache.removeChild(allRenamed[i].getName());
179
                    childrenCache.getChild(allRenamed[i].getName(), true);
180
                } finally {
181
                    if (mutexPrivileged != null) mutexPrivileged.exitWriteAccess();
182
                }                
183
            }
184
        }
185
        
166
        fireFileRenamedEvent(originalName, originalExt);
186
        fireFileRenamedEvent(originalName, originalExt);
167
    }
187
    }
168
188
Lines 353-360 Link Here
353
    public final FileNaming getFileName() {
373
    public final FileNaming getFileName() {
354
        return fileName;
374
        return fileName;
355
    }
375
    }
376
    
377
    public final void delete(final FileLock lock) throws IOException {
378
        delete(lock, null);
379
    }    
356
380
357
    public void delete(final FileLock lock) throws IOException {
381
    public void delete(final FileLock lock, ProvidedExtensions.DeleteHandler deleteHandler) throws IOException {        
358
        final File f = getFileName().getFile();
382
        final File f = getFileName().getFile();
359
383
360
        final FolderObj existingParent = getExistingParent();
384
        final FolderObj existingParent = getExistingParent();
Lines 367-379 Link Here
367
                FSException.io("EXC_InvalidLock", lock, getPath()); // NOI18N                
391
                FSException.io("EXC_InvalidLock", lock, getPath()); // NOI18N                
368
            }
392
            }
369
393
370
            if (!f.delete()) {
394
            boolean deleteStatus = (deleteHandler != null) ? deleteHandler.delete(f) : f.delete();
395
            if (!deleteStatus) {
371
                FileObject parent = getExistingParent();
396
                FileObject parent = getExistingParent();
372
                String parentPath = (parent != null) ? parent.getPath() : f.getParentFile().getAbsolutePath();
397
                String parentPath = (parent != null) ? parent.getPath() : f.getParentFile().getAbsolutePath();
373
                FSException.io("EXC_CannotDelete", f.getName(), parentPath);// NOI18N            
398
                FSException.io("EXC_CannotDelete", f.getName(), parentPath);// NOI18N            
374
            } 
399
            } 
375
            BaseFileObj.attribs.deleteAttributes(f.getAbsolutePath().replace('\\', '/'));//NOI18N
400
            BaseFileObj.attribs.deleteAttributes(f.getAbsolutePath().replace('\\', '/'));//NOI18N
376
            if (childrenCache != null) childrenCache.getChild(BaseFileObj.getNameExt(f), true);
401
            if (childrenCache != null) {
402
                if (deleteHandler != null) {
403
                    childrenCache.removeChild(BaseFileObj.getNameExt(f));
404
                } else {
405
                    childrenCache.getChild(BaseFileObj.getNameExt(f), true);
406
                }
407
            }
377
        } finally {
408
        } finally {
378
            if (mutexPrivileged != null) mutexPrivileged.exitWriteAccess();
409
            if (mutexPrivileged != null) mutexPrivileged.exitWriteAccess();
379
            setValid(false);
410
            setValid(false);
Lines 382-388 Link Here
382
        fireFileDeletedEvent(false);
413
        fireFileDeletedEvent(false);
383
414
384
    }
415
    }
385
416
    
386
    abstract boolean checkLock(FileLock lock) throws IOException;
417
    abstract boolean checkLock(FileLock lock) throws IOException;
387
418
388
    public Object writeReplace() {
419
    public Object writeReplace() {
Lines 392-397 Link Here
392
    abstract protected void setValid(boolean valid);
423
    abstract protected void setValid(boolean valid);
393
424
394
    abstract public void refresh(final boolean expected, boolean fire);
425
    abstract public void refresh(final boolean expected, boolean fire);
426
395
427
396
    //TODO: attributes written by VCS must be readable by FileBaseFS and vice versa  
428
    //TODO: attributes written by VCS must be readable by FileBaseFS and vice versa  
397
/**
429
/**
(-)src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObj.java (-2 / +2 lines)
Lines 210-217 Link Here
210
                setValid(false);
210
                setValid(false);
211
                if (fire) {
211
                if (fire) {
212
                    fireFileDeletedEvent(expected);
212
                    fireFileDeletedEvent(expected);
213
                }                
213
                }
214
            }            
214
            }
215
        }                 
215
        }                 
216
        stopWatch.stop();
216
        stopWatch.stop();
217
    }        
217
    }        
(-)src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObj.java (-9 / +20 lines)
Lines 34-39 Link Here
34
import java.io.*;
34
import java.io.*;
35
import java.util.*;
35
import java.util.*;
36
import org.netbeans.modules.masterfs.filebasedfs.naming.NamingFactory;
36
import org.netbeans.modules.masterfs.filebasedfs.naming.NamingFactory;
37
import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
37
38
38
/**
39
/**
39
 * @author rm111737
40
 * @author rm111737
Lines 214-231 Link Here
214
        }        
215
        }        
215
    }
216
    }
216
217
217
    public final void delete(final FileLock lock) throws IOException {
218
    public void delete(final FileLock lock, ProvidedExtensions.DeleteHandler deleteHandler) throws IOException {
218
        final LinkedList all = new LinkedList();
219
        final LinkedList all = new LinkedList();
219
220
220
        final File file = getFileName().getFile();
221
        final File file = getFileName().getFile();
221
        if (!deleteFile(file, all, getLocalFileSystem().getFactory())) {
222
        if (!deleteFile(file, all, getLocalFileSystem().getFactory(), deleteHandler)) {
222
            FileObject parent = getExistingParent();
223
            FileObject parent = getExistingParent();
223
            String parentPath = (parent != null) ? parent.getPath() : file.getParentFile().getAbsolutePath();
224
            String parentPath = (parent != null) ? parent.getPath() : file.getParentFile().getAbsolutePath();
224
            FSException.io("EXC_CannotDelete", file.getName(), parentPath);// NOI18N            
225
            FSException.io("EXC_CannotDelete", file.getName(), parentPath);// NOI18N            
225
        }
226
        }
226
227
227
        BaseFileObj.attribs.deleteAttributes(file.getAbsolutePath().replace('\\', '/'));//NOI18N
228
        BaseFileObj.attribs.deleteAttributes(file.getAbsolutePath().replace('\\', '/'));//NOI18N
228
229
        setValid(false);
229
        for (int i = 0; i < all.size(); i++) {
230
        for (int i = 0; i < all.size(); i++) {
230
            final BaseFileObj toDel = (BaseFileObj) all.get(i);            
231
            final BaseFileObj toDel = (BaseFileObj) all.get(i);            
231
            final FolderObj existingParent = toDel.getExistingParent();            
232
            final FolderObj existingParent = toDel.getExistingParent();            
Lines 233-240 Link Here
233
            if (childrenCache != null) {
234
            if (childrenCache != null) {
234
                final Mutex.Privileged mutexPrivileged = (childrenCache != null) ? childrenCache.getMutexPrivileged() : null;
235
                final Mutex.Privileged mutexPrivileged = (childrenCache != null) ? childrenCache.getMutexPrivileged() : null;
235
                if (mutexPrivileged != null) mutexPrivileged.enterWriteAccess();
236
                if (mutexPrivileged != null) mutexPrivileged.enterWriteAccess();
236
                try {                
237
                try {      
237
                    childrenCache.getChild(BaseFileObj.getNameExt(file), true);
238
                    if (deleteHandler != null) {
239
                        childrenCache.removeChild(BaseFileObj.getNameExt(file));
240
                    } else {
241
                        childrenCache.getChild(BaseFileObj.getNameExt(file), true);
242
                    }
243
                    
244
                    
238
                } finally {
245
                } finally {
239
                    if (mutexPrivileged != null) mutexPrivileged.exitWriteAccess();                    
246
                    if (mutexPrivileged != null) mutexPrivileged.exitWriteAccess();                    
240
                }
247
                }
Lines 344-351 Link Here
344
    }
351
    }
345
    
352
    
346
    //TODO: rewrite partly and check FileLocks for existing FileObjects
353
    //TODO: rewrite partly and check FileLocks for existing FileObjects
347
    private boolean deleteFile(final File file, final LinkedList all, final FileObjectFactory factory) throws IOException {
354
    private boolean deleteFile(final File file, final LinkedList all, final FileObjectFactory factory, ProvidedExtensions.DeleteHandler deleteHandler) throws IOException {
348
        final boolean ret = file.delete();
355
        final boolean ret = (deleteHandler != null) ? deleteHandler.delete(file) : file.delete();
349
356
350
        if (ret) {
357
        if (ret) {
351
            final FileObject aliveFo = factory.get(file);
358
            final FileObject aliveFo = factory.get(file);
Lines 364-370 Link Here
364
            final File[] arr = file.listFiles();
371
            final File[] arr = file.listFiles();
365
            for (int i = 0; i < arr.length; i++) {
372
            for (int i = 0; i < arr.length; i++) {
366
                final File f2Delete = arr[i];
373
                final File f2Delete = arr[i];
367
                if (!deleteFile(f2Delete, all, factory)) {
374
                if (!deleteFile(f2Delete, all, factory, deleteHandler)) {
368
                    return false;
375
                    return false;
369
                }
376
                }
370
            }
377
            }
Lines 374-380 Link Here
374
        //super.delete(lock());
381
        //super.delete(lock());
375
        
382
        
376
383
377
        final boolean retVal = file.delete();
384
        final boolean retVal = (deleteHandler != null) ? deleteHandler.delete(file) : file.delete();
378
        if (retVal) {
385
        if (retVal) {
379
            final FileObject aliveFo = factory.get(file);
386
            final FileObject aliveFo = factory.get(file);
380
            if (aliveFo != null) {
387
            if (aliveFo != null) {
Lines 473-478 Link Here
473
480
474
        public boolean existsInCache(String childName) {
481
        public boolean existsInCache(String childName) {
475
            return ch.existsldInCache(getFileName(), childName);
482
            return ch.existsldInCache(getFileName(), childName);
483
        }
484
485
        public void removeChild(String childName) {
486
            ch.removeChild(getFileName(), childName);
476
        }
487
        }
477
    }
488
    }
478
489
(-)src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/ReplaceForSerialization.java (-4 / +7 lines)
Lines 26-33 Link Here
26
import java.io.OutputStream;
26
import java.io.OutputStream;
27
import java.util.Date;
27
import java.util.Date;
28
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
28
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
29
import org.openide.filesystems.FileLock;
29
import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
30
import org.openide.filesystems.FileObject;
30
import org.openide.filesystems.*;
31
32
import java.io.*;
33
import java.util.Date;
31
34
32
/**
35
/**
33
 * @author Radek Matous
36
 * @author Radek Matous
Lines 57-66 Link Here
57
            super(file);
60
            super(file);
58
        }
61
        }
59
62
60
        public void delete(FileLock lock) throws IOException {
63
        public void delete(FileLock lock, ProvidedExtensions.IOHandler io) throws IOException {
61
            throw new IOException(getPath()); 
64
            throw new IOException(getPath()); 
62
        }
65
        }
63
66
        
64
        boolean checkLock(FileLock lock) throws IOException {
67
        boolean checkLock(FileLock lock) throws IOException {
65
            return false;
68
            return false;
66
        }
69
        }
(-)src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactory.java (-6 / +8 lines)
Lines 66-85 Link Here
66
        }                        
66
        }                        
67
    }
67
    }
68
68
69
    public static synchronized boolean rename (FileNaming fNaming, String newName) {        
69
    private static synchronized FileNaming[] rename (FileNaming fNaming, String newName) {        
70
        return rename(fNaming, newName, null);
70
        return rename(fNaming, newName, null);
71
    }
71
    }
72
    
72
    
73
    public static synchronized boolean rename (FileNaming fNaming, String newName, ProvidedExtensions.IOHandler handler) {
73
    public static synchronized FileNaming[] rename (FileNaming fNaming, String newName, ProvidedExtensions.IOHandler handler) {
74
        final ArrayList all = new ArrayList();
74
        boolean retVal = false;
75
        boolean retVal = false;
75
        remove(fNaming, null);
76
        remove(fNaming, null);
76
        retVal = fNaming.rename(newName, handler);
77
        retVal = fNaming.rename(newName, handler);
78
        all.add(fNaming);
77
        NamingFactory.registerInstanceOfFileNaming(fNaming.getParent(), fNaming.getFile(), fNaming);
79
        NamingFactory.registerInstanceOfFileNaming(fNaming.getParent(), fNaming.getFile(), fNaming);
78
        renameChildren();
80
        renameChildren(all);
79
        return retVal;
81
        return (retVal) ? ((FileNaming[])all.toArray(new FileNaming[all.size()])) : null;
80
    }
82
    }
81
83
82
    private static void renameChildren() {
84
    private static void renameChildren(final ArrayList all) {
83
        HashMap toRename = new HashMap ();
85
        HashMap toRename = new HashMap ();
84
        for (Iterator iterator = nameMap.entrySet().iterator(); iterator.hasNext();) {
86
        for (Iterator iterator = nameMap.entrySet().iterator(); iterator.hasNext();) {
85
            Map.Entry entry = (Map.Entry) iterator.next();
87
            Map.Entry entry = (Map.Entry) iterator.next();
Lines 101-107 Link Here
101
            Map.Entry entry = (Map.Entry) iterator.next();
103
            Map.Entry entry = (Map.Entry) iterator.next();
102
            Integer id = (Integer)entry.getKey();
104
            Integer id = (Integer)entry.getKey();
103
            FileNaming fN = (FileNaming)entry.getValue(); 
105
            FileNaming fN = (FileNaming)entry.getValue(); 
104
106
            all.add(fN);    
105
            remove(fN, id);
107
            remove(fN, id);
106
            fN.getId(true);
108
            fN.getId(true);
107
            NamingFactory.registerInstanceOfFileNaming(fN.getParent(), fN.getFile(), fN);            
109
            NamingFactory.registerInstanceOfFileNaming(fN.getParent(), fN.getFile(), fN);            
(-)src/org/netbeans/modules/masterfs/providers/ProvidedExtensions.java (+28 lines)
Lines 72-77 Link Here
72
            File from, String newName) {
72
            File from, String newName) {
73
        return null;
73
        return null;
74
    }
74
    }
75
76
    /*
77
     * Return instance of {@link ProvidedExtensions.DeleteHandler}
78
     * that is responsible for deleting the file or null.
79
     *
80
     * Just the first non null instance of <code>DeleteHandler</code> is used by
81
     *  <code>MasterFileSystem</code>
82
     *
83
     * @param f file or folder to be deleted
84
     * @return instance of {@link ProvidedExtensions.DeleteHandler} 
85
     * that is responsible for deleting the file or null
86
     */
87
    public ProvidedExtensions.DeleteHandler getDeleteHandler(File f) {
88
        return null;
89
    }
75
    
90
    
76
    
91
    
77
    public interface IOHandler {
92
    public interface IOHandler {
Lines 80-85 Link Here
80
         */
95
         */
81
        void handle() throws IOException;
96
        void handle() throws IOException;
82
    }
97
    }
98
    
99
    public interface DeleteHandler {
100
        /**
101
         * Deletes the file or directory denoted by this abstract pathname.  If
102
         * this pathname denotes a directory, then the directory must be empty in
103
         * order to be deleted.
104
         *
105
         * @return  <code>true</code> if and only if the file or directory is
106
         *          successfully deleted; <code>false</code> otherwise
107
         */
108
        boolean delete(File file);
109
    }
110
    
83
        
111
        
84
    public void createSuccess(FileObject fo) {}    
112
    public void createSuccess(FileObject fo) {}    
85
    public void createFailure(FileObject parent, String name, boolean isFolder) {}   
113
    public void createFailure(FileObject parent, String name, boolean isFolder) {}   
(-)test/unit/src/org/netbeans/modules/masterfs/CacheTest.java (-3 / +4 lines)
Lines 22-30 Link Here
22
import java.io.File;
22
import java.io.File;
23
import java.lang.ref.Reference;
23
import java.lang.ref.Reference;
24
import java.lang.ref.WeakReference;
24
import java.lang.ref.WeakReference;
25
import java.util.ArrayList;
26
import java.util.List;
27
import org.netbeans.junit.NbTestCase;
25
import org.netbeans.junit.NbTestCase;
26
import org.netbeans.modules.masterfs.providers.ProvidedExtensionsTest;
28
import org.openide.filesystems.FileObject;
27
import org.openide.filesystems.FileObject;
29
import org.openide.filesystems.FileUtil;
28
import org.openide.filesystems.FileUtil;
30
29
Lines 58-64 Link Here
58
        testFo.getFileSystem().findResource(testFo.getPath());        
57
        testFo.getFileSystem().findResource(testFo.getPath());        
59
                
58
                
60
        FileObject testFo2 = Cache.getDefault().getValidOrInvalid(((MasterFileObject)testFo).getResource());
59
        FileObject testFo2 = Cache.getDefault().getValidOrInvalid(((MasterFileObject)testFo).getResource());
61
        assertFalse(testFo2.isValid());
60
        if (!ProvidedExtensionsTest.ProvidedExtensionsImpl.isImplsDeleteRetVal()) {
61
            assertFalse(testFo2.isValid());
62
        }
62
        assertEquals(testFo, testFo2);        
63
        assertEquals(testFo, testFo2);        
63
    }
64
    }
64
    
65
    
(-)test/unit/src/org/netbeans/modules/masterfs/MasterFileObjectTestHid.java (-7 / +14 lines)
Lines 37-42 Link Here
37
37
38
import javax.swing.filechooser.FileSystemView;
38
import javax.swing.filechooser.FileSystemView;
39
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.WriteLockUtils;
39
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.WriteLockUtils;
40
import org.netbeans.modules.masterfs.providers.ProvidedExtensionsTest;
40
41
41
public class MasterFileObjectTestHid extends TestBaseHid{
42
public class MasterFileObjectTestHid extends TestBaseHid{
42
    private FileObject root;
43
    private FileObject root;
Lines 443-450 Link Here
443
            }            
444
            }            
444
        });                        
445
        });                        
445
        
446
        
446
        assertNotNull(fo.getFileObject("newchild.txt"));
447
        if (!ProvidedExtensionsTest.ProvidedExtensionsImpl.isImplsDeleteRetVal()) {
447
        assertTrue(list.size() == 1);
448
            assertNotNull(fo.getFileObject("newchild.txt"));
449
            assertTrue(list.size() == 1);
450
        }
448
        fo.removeFileChangeListener(fcl);
451
        fo.removeFileChangeListener(fcl);
449
    }
452
    }
450
        
453
        
Lines 547-556 Link Here
547
        
550
        
548
        MountTable mt = MountTable.getDefault();
551
        MountTable mt = MountTable.getDefault();
549
        mt.mount(mountFile.getAbsolutePath(), ifs);
552
        mt.mount(mountFile.getAbsolutePath(), ifs);
550
        
553
551
        mountDir.delete();
554
        if (!ProvidedExtensionsTest.ProvidedExtensionsImpl.isImplsDeleteRetVal()) {
552
        assertTrue(!mountDir.isValid());
555
            mountDir.delete();
553
        assertNull(root.getFileObject("testdir/mountdir"));
556
            assertTrue(!mountDir.isValid());
557
            assertNull(root.getFileObject("testdir/mountdir"));
558
        }
554
    }
559
    }
555
560
556
    public void testDeleteCaptureExteralChanges () throws Exception {
561
    public void testDeleteCaptureExteralChanges () throws Exception {
Lines 565-571 Link Here
565
        assertTrue(f.exists());
570
        assertTrue(f.exists());
566
        assertTrue (f.delete());
571
        assertTrue (f.delete());
567
        
572
        
568
        assertFalse(fileObject.isValid());       
573
        if (!ProvidedExtensionsTest.ProvidedExtensionsImpl.isImplsDeleteRetVal()) {        
574
            assertFalse(fileObject.isValid());       
575
        }
569
    }
576
    }
570
        
577
        
571
    public void testFindResourceCaptureExteralChanges () throws Exception {
578
    public void testFindResourceCaptureExteralChanges () throws Exception {
(-)test/unit/src/org/netbeans/modules/masterfs/MasterFileSystemTest.java (-1 / +1 lines)
Lines 58-64 Link Here
58
        super(test);
58
        super(test);
59
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsMoveRetVal(false);
59
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsMoveRetVal(false);
60
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsRenameRetVal(false);
60
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsRenameRetVal(false);
61
61
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsDeleteRetVal(false);        
62
    }
62
    }
63
63
64
64
(-)test/unit/src/org/netbeans/modules/masterfs/MasterFileSystemWithExtensionsTest.java (-1 / +2 lines)
Lines 30-36 Link Here
30
    public MasterFileSystemWithExtensionsTest(Test test) {
30
    public MasterFileSystemWithExtensionsTest(Test test) {
31
        super(test);
31
        super(test);
32
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsMoveRetVal(true);
32
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsMoveRetVal(true);
33
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsRenameRetVal(true);
33
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsRenameRetVal(true);        
34
        ProvidedExtensionsTest.ProvidedExtensionsImpl.setImplsDeleteRetVal(true);                
34
    }
35
    }
35
36
36
    public static Test suite() {
37
    public static Test suite() {
(-)test/unit/src/org/netbeans/modules/masterfs/providers/ProvidedExtensionsTest.java (-1 / +37 lines)
Lines 20-25 Link Here
20
package org.netbeans.modules.masterfs.providers;
20
package org.netbeans.modules.masterfs.providers;
21
21
22
import java.io.File;
22
import java.io.File;
23
import java.io.FileFilter;
23
import java.io.FileInputStream;
24
import java.io.FileInputStream;
24
import java.io.FileOutputStream;
25
import java.io.FileOutputStream;
25
import java.io.IOException;
26
import java.io.IOException;
Lines 27-34 Link Here
27
import java.io.OutputStream;
28
import java.io.OutputStream;
28
import java.util.ArrayList;
29
import java.util.ArrayList;
29
import java.util.Collection;
30
import java.util.Collection;
31
import java.util.HashSet;
30
import java.util.Iterator;
32
import java.util.Iterator;
31
import java.util.List;
33
import java.util.List;
34
import java.util.Set;
32
import junit.framework.AssertionFailedError;
35
import junit.framework.AssertionFailedError;
33
import org.netbeans.junit.NbTestCase;
36
import org.netbeans.junit.NbTestCase;
34
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
37
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
Lines 368-373 Link Here
368
        
371
        
369
        private static  boolean implsMoveRetVal = true;
372
        private static  boolean implsMoveRetVal = true;
370
        private static boolean implsRenameRetVal = true;
373
        private static boolean implsRenameRetVal = true;
374
        private static boolean implsDeleteRetVal = true;
371
        
375
        
372
        public static FileLock lock;
376
        public static FileLock lock;
373
        
377
        
Lines 377-383 Link Here
377
            implsRenameCalls = 0;
381
            implsRenameCalls = 0;
378
            renameImplCalls = 0;
382
            renameImplCalls = 0;
379
        }
383
        }
380
        
384
385
        public ProvidedExtensions.DeleteHandler getDeleteHandler(File f) {
386
            return (!isImplsDeleteRetVal()) ? null : new ProvidedExtensions.DeleteHandler(){
387
                final Set s = new HashSet();
388
                public boolean delete(File file) {
389
                    if (file.isDirectory()) {
390
                        File[] childs = file.listFiles(new FileFilter() {
391
                            public boolean accept(File pathname) {
392
                                boolean accepted = pathname.isFile();
393
                                if (!accepted && pathname.isDirectory()) {
394
                                    accepted = !s.contains(pathname);
395
                                    if (!s.contains(pathname)) {
396
                                        s.add(pathname);
397
                                    }
398
                                } 
399
                                return accepted;
400
                            }
401
                        });
402
                        return childs.length == 0;
403
                    }
404
                    return file.delete();
405
                }                
406
            };
407
        }
408
                
381
        public ProvidedExtensions.IOHandler getRenameHandler(final File from, final String newName) {
409
        public ProvidedExtensions.IOHandler getRenameHandler(final File from, final String newName) {
382
            implsRenameCalls++;
410
            implsRenameCalls++;
383
            final File f = new File(from.getParentFile(),newName);
411
            final File f = new File(from.getParentFile(),newName);
Lines 441-445 Link Here
441
        public static void setImplsRenameRetVal(boolean implsRenameRetVal) {
469
        public static void setImplsRenameRetVal(boolean implsRenameRetVal) {
442
            ProvidedExtensionsImpl.implsRenameRetVal = implsRenameRetVal;
470
            ProvidedExtensionsImpl.implsRenameRetVal = implsRenameRetVal;
443
        }
471
        }
472
               
473
        public static boolean isImplsDeleteRetVal() {
474
            return implsDeleteRetVal;
475
        }
476
        
477
        public static void setImplsDeleteRetVal(boolean implsDeleteRetVal) {
478
            ProvidedExtensionsImpl.implsDeleteRetVal = implsDeleteRetVal;
479
        }                
444
    }
480
    }
445
}
481
}

Return to bug 81510