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

(-)a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/BaseFileObj.java (+11 lines)
Lines 203-208 Link Here
203
    public final boolean isRoot() {
203
    public final boolean isRoot() {
204
        return false;
204
        return false;
205
    }
205
    }
206
207
    public final java.util.Date lastModified() {
208
        final File f = getFileName().getFile();
209
        final long lastModified = f.lastModified();
210
211
        final FolderObj fo = getExistingParent();
212
        if (fo != null) {
213
            fo.storeTimeStamps(lastModified);
214
        }
215
        return new Date(lastModified);
216
    }
206
     
217
     
207
    @Override
218
    @Override
208
    public final FileObject move(FileLock lock, FileObject target, String name, String ext) throws IOException {
219
    public final FileObject move(FileLock lock, FileObject target, String name, String ext) throws IOException {
(-)a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObj.java (-5 lines)
Lines 210-220 Link Here
210
        return super.canWrite();
210
        return super.canWrite();
211
    }
211
    }
212
        
212
        
213
    public final Date lastModified() {
214
        final File f = getFileName().getFile();
215
        return new Date(f.lastModified());
216
    }
217
218
    final void setLastModified(long lastModified) {
213
    final void setLastModified(long lastModified) {
219
        if (this.lastModified != 0) { // #130998 - don't set when already invalidated
214
        if (this.lastModified != 0) { // #130998 - don't set when already invalidated
220
            if (this.lastModified != -1 && !realLastModifiedCached) {
215
            if (this.lastModified != -1 && !realLastModifiedCached) {
(-)a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObj.java (-5 / +31 lines)
Lines 49-54 Link Here
49
import java.io.SyncFailedException;
49
import java.io.SyncFailedException;
50
import java.util.ArrayList;
50
import java.util.ArrayList;
51
import java.util.Date;
51
import java.util.Date;
52
import java.util.Enumeration;
52
import java.util.HashSet;
53
import java.util.HashSet;
53
import java.util.Iterator;
54
import java.util.Iterator;
54
import java.util.LinkedList;
55
import java.util.LinkedList;
Lines 62-67 Link Here
62
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem.FSCallable;
63
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem.FSCallable;
63
import org.netbeans.modules.masterfs.filebasedfs.children.ChildrenCache;
64
import org.netbeans.modules.masterfs.filebasedfs.children.ChildrenCache;
64
import org.netbeans.modules.masterfs.filebasedfs.children.ChildrenSupport;
65
import org.netbeans.modules.masterfs.filebasedfs.children.ChildrenSupport;
66
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObjectFactory.Caller;
65
import org.netbeans.modules.masterfs.filebasedfs.naming.FileName;
67
import org.netbeans.modules.masterfs.filebasedfs.naming.FileName;
66
import org.netbeans.modules.masterfs.filebasedfs.naming.FileNaming;
68
import org.netbeans.modules.masterfs.filebasedfs.naming.FileNaming;
67
import org.netbeans.modules.masterfs.filebasedfs.naming.NamingFactory;
69
import org.netbeans.modules.masterfs.filebasedfs.naming.NamingFactory;
Lines 82-88 Link Here
82
    private static final Mutex mutex = new Mutex(FolderObj.mp);
84
    private static final Mutex mutex = new Mutex(FolderObj.mp);
83
85
84
    private FolderChildrenCache folderChildren;
86
    private FolderChildrenCache folderChildren;
85
    boolean valid = true;    
87
    boolean valid = true;
88
    private long childrenStamps = -1;
86
89
87
    /**
90
    /**
88
     * Creates a new instance of FolderImpl
91
     * Creates a new instance of FolderImpl
Lines 330-338 Link Here
330
        }        
333
        }        
331
    }
334
    }
332
335
336
    final void storeTimeStamps(long lastModified) {
337
        if (lastModified > childrenStamps) {
338
            childrenStamps = lastModified;
339
        }
340
    }
341
342
343
333
    public void refreshImpl(final boolean expected, boolean fire) {
344
    public void refreshImpl(final boolean expected, boolean fire) {
334
        final ChildrenCache cache = getChildrenCache();
345
        final ChildrenCache cache = getChildrenCache();
335
        final Mutex.Privileged mutexPrivileged = cache.getMutexPrivileged();
346
        final Mutex.Privileged mutexPrivileged = cache.getMutexPrivileged();
347
        final long previous = childrenStamps;
336
348
337
        Set oldChildren = null;
349
        Set oldChildren = null;
338
        Map refreshResult = null;
350
        Map refreshResult = null;
Lines 412-417 Link Here
412
                fireFileDeletedEvent(expected);
424
                fireFileDeletedEvent(expected);
413
            }
425
            }
414
        }
426
        }
427
428
        if (childrenStamps > 0) {
429
            long highest = 0;
430
            final File[] arr = getFileName().getFile().listFiles();
431
            if (arr != null) {
432
                for (File f : arr) {
433
                    final long time = f.lastModified();
434
                    if (time > highest) {
435
                        highest = time;
436
                    }
437
                    if (time > previous) {
438
                        BaseFileObj who = factory.getValidFileObject(f, Caller.Others);
439
                        who.fireFileChangedEvent(false);
440
                    }
441
                    childrenStamps = highest;
442
                }
443
            }
444
        }
415
    }
445
    }
416
446
417
    @Override
447
    @Override
Lines 487-496 Link Here
487
        throw new IOException(getPath());
517
        throw new IOException(getPath());
488
    }
518
    }
489
519
490
    public final java.util.Date lastModified() {
491
        final File f = getFileName().getFile();
492
        return new Date(f.lastModified());
493
    }
494
520
495
    public final FileLock lock() throws IOException {
521
    public final FileLock lock() throws IOException {
496
        return new FileLock();
522
        return new FileLock();
(-)a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/ReplaceForSerialization.java (-4 lines)
Lines 91-100 Link Here
91
            return false;
91
            return false;
92
        }
92
        }
93
93
94
        public Date lastModified() {
95
            return new Date(0L);
96
        }
97
98
        /* Test whether the file is valid. The file can be invalid if it has been deserialized
94
        /* Test whether the file is valid. The file can be invalid if it has been deserialized
99
        * and the file no longer exists on disk; or if the file has been deleted.
95
        * and the file no longer exists on disk; or if the file has been deleted.
100
        *
96
        *
(-)a9b41094a261 (+185 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.masterfs.filebasedfs.fileobjects;
42
43
import java.io.File;
44
import java.io.FileOutputStream;
45
import java.lang.ref.Reference;
46
import java.lang.ref.WeakReference;
47
import java.util.Date;
48
import org.netbeans.junit.NbTestCase;
49
import org.openide.filesystems.FileChangeAdapter;
50
import org.openide.filesystems.FileEvent;
51
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
53
54
public class ExternalTouchTest extends NbTestCase {
55
56
    public ExternalTouchTest(String testName) {
57
        super(testName);
58
    }
59
60
    public void testChangeInChildrenNoticed() throws Exception {
61
        clearWorkDir();
62
        FileObject testFolder = FileUtil.toFileObject(getWorkDir());
63
        
64
        FileObject fileObject1 = testFolder.createData("fileObject1");
65
        final Date lm = fileObject1.lastModified();
66
        assertNotNull("Just to initialize the stamp", lm);
67
        FileObject[] arr = testFolder.getChildren();
68
        assertEquals("One child", 1, arr.length);
69
        assertEquals("Right child", fileObject1, arr[0]);
70
71
        File file = FileUtil.toFile(fileObject1);
72
        assertNotNull("File found", file);
73
        Reference<FileObject> ref = new WeakReference<FileObject>(fileObject1);
74
        arr = null;
75
        fileObject1 = null;
76
        assertGC("File Object can disappear", ref);
77
78
        Thread.sleep(1000);
79
        
80
        class L extends FileChangeAdapter {
81
            int cnt;
82
            FileEvent event;
83
            
84
            @Override
85
            public void fileChanged(FileEvent fe) {
86
                cnt++;
87
                event = fe;
88
            }
89
        }
90
        L listener = new L();
91
        testFolder.addFileChangeListener(listener);
92
93
        FileOutputStream os = new FileOutputStream(file);
94
        os.write(10);
95
        os.close();
96
97
        if (lm.getTime() > file.lastModified() - 50) {
98
            fail("New modification time shall be at last 50ms after the original one: " + (file.lastModified() - lm.getTime()));
99
        }
100
101
        testFolder.refresh();
102
103
        assertEquals("Change notified", 1, listener.cnt);
104
        assertEquals("Right file", file, FileUtil.toFile(listener.event.getFile()));
105
    }
106
    public void testNewChildNoticed() throws Exception {
107
        clearWorkDir();
108
        FileObject testFolder = FileUtil.toFileObject(getWorkDir());
109
        FileObject fileObject1 = testFolder.createData("fileObject1");
110
        assertNotNull("Just to initialize the stamp", fileObject1.lastModified());
111
        FileObject[] arr = testFolder.getChildren();
112
        assertEquals("One child", 1, arr.length);
113
        assertEquals("Right child", fileObject1, arr[0]);
114
115
        File file = FileUtil.toFile(fileObject1);
116
        assertNotNull("File found", file);
117
        arr = null;
118
        fileObject1 = null;
119
        Reference<FileObject> ref = new WeakReference<FileObject>(fileObject1);
120
        assertGC("File Object can disappear", ref);
121
122
        Thread.sleep(100);
123
124
        class L extends FileChangeAdapter {
125
            int cnt;
126
            FileEvent event;
127
128
            @Override
129
            public void fileDataCreated(FileEvent fe) {
130
                cnt++;
131
                event = fe;
132
            }
133
134
        }
135
        L listener = new L();
136
        testFolder.addFileChangeListener(listener);
137
138
        File nfile = new File(file.getParentFile(), "new.txt");
139
        nfile.createNewFile();
140
141
        testFolder.refresh();
142
143
        assertEquals("Change notified", 1, listener.cnt);
144
        assertEquals("Right file", nfile, FileUtil.toFile(listener.event.getFile()));
145
    }
146
    public void testDeleteOfAChildNoticed() throws Exception {
147
        clearWorkDir();
148
        FileObject testFolder = FileUtil.toFileObject(getWorkDir());
149
        FileObject fileObject1 = testFolder.createData("fileObject1");
150
        assertNotNull("Just to initialize the stamp", fileObject1.lastModified());
151
        FileObject[] arr = testFolder.getChildren();
152
        assertEquals("One child", 1, arr.length);
153
        assertEquals("Right child", fileObject1, arr[0]);
154
155
        File file = FileUtil.toFile(fileObject1);
156
        assertNotNull("File found", file);
157
        arr = null;
158
        fileObject1 = null;
159
        Reference<FileObject> ref = new WeakReference<FileObject>(fileObject1);
160
        assertGC("File Object can disappear", ref);
161
162
        Thread.sleep(100);
163
164
        class L extends FileChangeAdapter {
165
            int cnt;
166
            FileEvent event;
167
168
            @Override
169
            public void fileDeleted(FileEvent fe) {
170
                cnt++;
171
                event = fe;
172
            }
173
174
        }
175
        L listener = new L();
176
        testFolder.addFileChangeListener(listener);
177
178
        file.delete();
179
180
        testFolder.refresh();
181
182
        assertEquals("Change notified", 1, listener.cnt);
183
        assertEquals("Right file", file, FileUtil.toFile(listener.event.getFile()));
184
    }
185
}

Return to bug 170727