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() { |