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

(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/DirectoryStorage.java (-1 / +48 lines)
Lines 51-58 Link Here
51
import java.util.ArrayList;
51
import java.util.ArrayList;
52
import java.util.Collection;
52
import java.util.Collection;
53
import java.util.HashMap;
53
import java.util.HashMap;
54
import java.util.HashSet;
54
import java.util.List;
55
import java.util.List;
55
import java.util.Map;
56
import java.util.Map;
57
import java.util.Set;
56
58
57
/**
59
/**
58
 * Keeps information about all files that reside in the directory
60
 * Keeps information about all files that reside in the directory
Lines 61-68 Link Here
61
public final class DirectoryStorage {
63
public final class DirectoryStorage {
62
64
63
    private final Map<String, DirEntry> entries;
65
    private final Map<String, DirEntry> entries;
66
    /** known inexistent files in the case of r/o directory - see #196841 - remote FS doesn't work if any part of path to file does not have read permission */
67
    private final Set<String> dummies = new HashSet<String>();
64
    private final File cacheFile;
68
    private final File cacheFile;
65
    private static final int VERSION = RemoteDirectory.getLsViaSftp() ? 3 : 2;
69
    private static final int VERSION = RemoteDirectory.getLsViaSftp() ? 4 : 3;
66
    /* Incompatible version to discard */
70
    /* Incompatible version to discard */
67
    private static final int ODD_VERSION = RemoteDirectory.getLsViaSftp() ? 3 : 2;
71
    private static final int ODD_VERSION = RemoteDirectory.getLsViaSftp() ? 3 : 2;
68
72
Lines 72-82 Link Here
72
    }
76
    }
73
77
74
    public DirectoryStorage(File file, Collection<DirEntry> newEntries) {
78
    public DirectoryStorage(File file, Collection<DirEntry> newEntries) {
79
        this(file, newEntries, null);
80
    }
81
82
    public DirectoryStorage(File file, Collection<DirEntry> newEntries, Collection<String> newDummies) {
75
        this.cacheFile = file;
83
        this.cacheFile = file;
76
        this.entries = new HashMap<String, DirEntry>();
84
        this.entries = new HashMap<String, DirEntry>();
77
        for (DirEntry entry : newEntries) {
85
        for (DirEntry entry : newEntries) {
78
            entries.put(entry.getName(), entry);
86
            entries.put(entry.getName(), entry);
79
        }
87
        }
88
        if (newDummies != null) {
89
            dummies.addAll(newDummies);
90
        }
80
    }
91
    }
81
    
92
    
82
    /**
93
    /**
Lines 114-119 Link Here
114
                    throw new FormatException("Discarding old directory cache file version " + version +  //NNOI18N
125
                    throw new FormatException("Discarding old directory cache file version " + version +  //NNOI18N
115
                            ' ' + cacheFile.getAbsolutePath(), true); //NOI18N
126
                            ' ' + cacheFile.getAbsolutePath(), true); //NOI18N
116
                }
127
                }
128
                line = br.readLine();
129
                prefix = "dummies="; // NOI18N
130
                if (line == null || ! line.startsWith(prefix)) {
131
                    throw new FormatException("Wrong file format " + cacheFile.getAbsolutePath() + " line " + line, false); //NOI18N)
132
                }
133
                int dummiesCount;
134
                try {
135
                    dummiesCount = Integer.parseInt(line.substring(prefix.length()));
136
                } catch (NumberFormatException nfe) {
137
                    throw new FormatException("wrong dummies count format " + cacheFile.getAbsolutePath(), nfe); // NOI18N
138
                }
139
                for (int i = 0; i < dummiesCount; i++) {
140
                    line = br.readLine();
141
                    if (line == null) {
142
                        throw new FormatException("premature end of file " + cacheFile.getAbsolutePath(), false); // NOI18N
143
                    } else {
144
                        dummies.add(line);
145
                    }
146
                }
117
                while ((line = br.readLine()) != null) {
147
                while ((line = br.readLine()) != null) {
118
                    if (line.length() == 0) {
148
                    if (line.length() == 0) {
119
                        continue; // just in case, ignore empty lines
149
                        continue; // just in case, ignore empty lines
Lines 138-149 Link Here
138
        }
168
        }
139
    }
169
    }
140
    
170
    
171
    public boolean isKnown(String fileName) {
172
        synchronized (this) {
173
            return entries.containsKey(fileName) || dummies.contains(fileName);
174
        }
175
    }
176
    
141
    public void store() throws IOException {
177
    public void store() throws IOException {
142
        BufferedWriter wr = null;
178
        BufferedWriter wr = null;
143
        synchronized (this) {
179
        synchronized (this) {
144
            try {
180
            try {
145
                wr = new BufferedWriter(new FileWriter(cacheFile));
181
                wr = new BufferedWriter(new FileWriter(cacheFile));
146
                wr.write("VERSION=" + VERSION + "\n"); //NOI18N
182
                wr.write("VERSION=" + VERSION + "\n"); //NOI18N
183
                wr.write("dummies=" + dummies.size() + '\n'); //NOI18N
184
                for (String dummy: dummies) {
185
                    wr.write(dummy);
186
                    wr.write('\n');
187
                }
147
                for (DirEntry entry : entries.values()) {
188
                for (DirEntry entry : entries.values()) {
148
                    wr.write(entry.toExternalForm());
189
                    wr.write(entry.toExternalForm());
149
                    wr.write('\n');
190
                    wr.write('\n');
Lines 187-192 Link Here
187
            entries.put(entry.getName(), entry);
228
            entries.put(entry.getName(), entry);
188
        }
229
        }
189
    }
230
    }
231
    
232
    /*package*/ void testAddDummy(String dummy) {
233
        synchronized (this) {
234
            dummies.add(dummy);
235
        }
236
    }
190
237
191
    @Override
238
    @Override
192
    public String toString() {
239
    public String toString() {
(-)a/dlight.remote.impl/test/unit/src/org/netbeans/modules/remote/impl/fs/DirectoryStorageLsTestCase.java (+5 lines)
Lines 85-90 Link Here
85
            final String link = null;
85
            final String link = null;
86
            entry1 = new DirEntryLs(name, cacheName, access, user, group, size, timestamp, link);
86
            entry1 = new DirEntryLs(name, cacheName, access, user, group, size, timestamp, link);
87
            ds1.testAddEntry(entry1);
87
            ds1.testAddEntry(entry1);
88
            String dummy = "inexistent_file";
89
            ds1.testAddDummy(dummy);
88
            ds1.store();
90
            ds1.store();
89
            DirectoryStorage ds2 = new DirectoryStorage(file);
91
            DirectoryStorage ds2 = new DirectoryStorage(file);
90
            ds2.load();
92
            ds2.load();
Lines 98-103 Link Here
98
            assertEquals("Size", size, entry2.getSize());
100
            assertEquals("Size", size, entry2.getSize());
99
            assertEquals("Timestamp", entry1.getLastModified(), entry2.getLastModified());
101
            assertEquals("Timestamp", entry1.getLastModified(), entry2.getLastModified());
100
            assertEquals("Link", link, entry2.getLinkTarget());
102
            assertEquals("Link", link, entry2.getLinkTarget());
103
            assertTrue(ds2.isKnown(dummy));
104
            assertFalse(ds2.isKnown("abrakadabra"));
105
            assertTrue(ds2.isKnown(entry2.getName()));
101
        } finally {
106
        } finally {
102
            file.delete();
107
            file.delete();
103
        }
108
        }
(-)a/dlight.remote.impl/test/unit/src/org/netbeans/modules/remote/impl/fs/DirectoryStorageSftpTestCase.java (-2 / +5 lines)
Lines 91-109 Link Here
91
            final String cacheName = "name.cache";
91
            final String cacheName = "name.cache";
92
            DirEntry entry1 = new DirEntrySftp(statInfo, cacheName);
92
            DirEntry entry1 = new DirEntrySftp(statInfo, cacheName);
93
            ds1.testAddEntry(entry1);
93
            ds1.testAddEntry(entry1);
94
            String dummy = "inexistent_file";
95
            ds1.testAddDummy(dummy);
94
            ds1.store();
96
            ds1.store();
95
            DirectoryStorage ds2 = new DirectoryStorage(file);
97
            DirectoryStorage ds2 = new DirectoryStorage(file);
96
            ds2.load();
98
            ds2.load();
97
            DirEntry entry2 = ds2.getEntry(entry1.getName());
99
            DirEntry entry2 = ds2.getEntry(entry1.getName());
98
            assertNotNull("No entry restored for " + entry1.getName(), entry2);
100
            assertNotNull("No entry restored for " + entry1.getName(), entry2);
99
            
100
            assertEquals("Name", entry1.getName(), entry2.getName());
101
            assertEquals("Name", entry1.getName(), entry2.getName());
101
            assertEquals("Cache", entry1.getCache(), entry2.getCache());
102
            assertEquals("Cache", entry1.getCache(), entry2.getCache());
102
            assertEquals("Access", entry1.getAccessAsString(), entry2.getAccessAsString());
103
            assertEquals("Access", entry1.getAccessAsString(), entry2.getAccessAsString());
103
            assertEquals("Size", entry1.getSize(), entry2.getSize());
104
            assertEquals("Size", entry1.getSize(), entry2.getSize());
104
            assertTrue("Timestamps differ", entry1.isSameLastModified(entry2));
105
            assertTrue("Timestamps differ", entry1.isSameLastModified(entry2));
105
            assertEquals("Link", entry1.getLinkTarget(), entry2.getLinkTarget());
106
            assertEquals("Link", entry1.getLinkTarget(), entry2.getLinkTarget());
106
            
107
            assertTrue(ds2.isKnown(dummy));
108
            assertFalse(ds2.isKnown("abrakadabra"));
109
            assertTrue(ds2.isKnown(entry2.getName()));
107
        } finally {
110
        } finally {
108
            file.delete();
111
            file.delete();
109
        }
112
        }

Return to bug 196841