# HG changeset patch # User Vladimir Kvashin # Date 1300905718 -10800 # Node ID bcf92b3a28002fae9421eb6153a8f51731f55a8d # Parent 7feefeae05af1c2a86bf65f14337985c6d096fbd fix prototype for #196841 - remote FS doesn't work if any part of path to file does not have read permission diff -r 7feefeae05af -r bcf92b3a2800 dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java --- a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java Wed Mar 23 21:16:03 2011 +0300 +++ b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java Wed Mar 23 21:41:58 2011 +0300 @@ -50,6 +50,7 @@ import java.io.InputStream; import java.io.InterruptedIOException; import java.io.OutputStream; +import java.io.PrintWriter; import java.lang.ref.Reference; import java.lang.ref.SoftReference; import java.net.ConnectException; @@ -70,6 +71,8 @@ import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport; import org.netbeans.modules.nativeexecution.api.util.ConnectionManager; +import org.netbeans.modules.nativeexecution.api.util.FileInfoProvider; +import org.netbeans.modules.nativeexecution.api.util.FileInfoProvider.StatInfo; import org.netbeans.modules.nativeexecution.api.util.ProcessUtils; import org.netbeans.modules.remote.support.RemoteLogger; import org.openide.filesystems.FileEvent; @@ -112,7 +115,7 @@ /*package*/ boolean canWrite(String childNameExt) throws IOException, ConnectException { try { - DirectoryStorage storage = getDirectoryStorage(); + DirectoryStorage storage = getDirectoryStorage(childNameExt); DirEntry entry = storage.getEntry(childNameExt); return entry != null && entry.canWrite(getExecutionEnvironment()); //TODO:rfs - check groups } catch (ConnectException ex) { @@ -133,7 +136,7 @@ /*package*/ boolean canRead(String childNameExt) throws IOException { try { - DirectoryStorage storage = getDirectoryStorage(); + DirectoryStorage storage = getDirectoryStorage(childNameExt); DirEntry entry = storage.getEntry(childNameExt); return entry != null && entry.canRead(getExecutionEnvironment()); } catch (ConnectException ex) { @@ -271,7 +274,7 @@ } RemoteLogger.assertTrue(slashPos == -1); try { - DirectoryStorage storage = getDirectoryStorage(); + DirectoryStorage storage = getDirectoryStorage(relativePath); DirEntry entry = storage.getEntry(relativePath); if (entry == null) { return null; @@ -385,9 +388,14 @@ private DirectoryStorage getDirectoryStorage() throws ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { + return getDirectoryStorage(null); + } + + private DirectoryStorage getDirectoryStorage(String childName) throws + ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { long time = System.currentTimeMillis(); try { - return getDirectoryStorageImpl(false, null); + return getDirectoryStorageImpl(false, null, childName); } finally { if (trace) { trace("getDirectoryStorage for {1} took {0} ms", this, System.currentTimeMillis() - time); // NOI18N @@ -399,7 +407,7 @@ ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { long time = System.currentTimeMillis(); try { - return getDirectoryStorageImpl(true, expectedName); + return getDirectoryStorageImpl(true, expectedName, null); } finally { if (trace) { trace("refreshDirectoryStorage for {1} took {0} ms", this, System.currentTimeMillis() - time); // NOI18N @@ -407,7 +415,7 @@ } } - private DirectoryStorage getDirectoryStorageImpl(boolean force, String expectedName) throws + private DirectoryStorage getDirectoryStorageImpl(boolean force, String expectedName, String childName) throws ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { if (force && ! ConnectionManager.getInstance().isConnectedTo(getExecutionEnvironment())) { @@ -503,11 +511,21 @@ throw new IOException("Can not create cache directory " + getCache()); // NOI18N } } - DirectoryReader directoryReader = getLsViaSftp() ? - new DirectoryReaderSftp(getExecutionEnvironment(), getPath()) : new DirectoryReaderLs(getExecutionEnvironment(), getPath()); + List readEntries = new ArrayList(); if (trace) { trace("synchronizing"); } // NOI18N try { - directoryReader.readDirectory(); + if (canRead()) { + DirectoryReader directoryReader = getLsViaSftp() ? + new DirectoryReaderSftp(getExecutionEnvironment(), getPath()) : new DirectoryReaderLs(getExecutionEnvironment(), getPath()); + directoryReader.readDirectory(); + readEntries = directoryReader.getEntries(); + } else { + if (childName != null) { + Future stat = FileInfoProvider.stat(getExecutionEnvironment(), getPath() + '/' + childName, new PrintWriter(System.err)); + DirEntry entry = new DirEntrySftp(stat.get(), childName); + readEntries.add(entry); + } + } } catch (FileNotFoundException ex) { throw ex; } catch (IOException ex) { @@ -537,8 +555,8 @@ getFileSystem().incrementDirSyncCount(); Map> dupLowerNames = new HashMap>(); boolean hasDups = false; - Map newEntries = new HashMap(); - for (DirEntry entry : directoryReader.getEntries()) { + Map newEntries = new HashMap(); + for (DirEntry entry : readEntries) { newEntries.put(entry.getName(), entry); } boolean changed = (newEntries.size() != storage.size()); @@ -679,7 +697,7 @@ lock.unlock(); } checkConnection(child, true); - DirectoryStorage storage = getDirectoryStorage(); // do we need this? + DirectoryStorage storage = getDirectoryStorage(child.getNameExt()); // do we need this? return new CachedRemoteInputStream(child, getExecutionEnvironment()); } @@ -696,7 +714,7 @@ lock.unlock(); } checkConnection(child, true); - DirectoryStorage storage = getDirectoryStorage(); // do we need this? + DirectoryStorage storage = getDirectoryStorage(child.getNameExt()); // do we need this? lock = RemoteFileSystem.getLock(child.getCache()).writeLock(); lock.lock(); try { @@ -807,7 +825,7 @@ private DirEntry getChildEntry(RemoteFileObjectBase child) { try { - DirectoryStorage directoryStorage = getDirectoryStorage(); + DirectoryStorage directoryStorage = getDirectoryStorage(child.getNameExt()); if (directoryStorage != null) { DirEntry entry = directoryStorage.getEntry(child.getNameExt()); if (entry != null) {