~xdavidwu/saf-sftp

af6631405f51b766f86bfd189f009ab4e41c89f9 — xdavidwu 1 year, 8 months ago 3a1020c
SFTPDocumentsProvider: correct connection resetting
1 files changed, 5 insertions(+), 7 deletions(-)

M src/main/java/org/safsftp/SFTPDocumentsProvider.java
M src/main/java/org/safsftp/SFTPDocumentsProvider.java => src/main/java/org/safsftp/SFTPDocumentsProvider.java +5 -7
@@ 94,6 94,7 @@ public class SFTPDocumentsProvider extends DocumentsProvider {
			} catch (IOException e) {
				// continue with new connection attempt
			}
			connection.close();
		}
		SharedPreferences settings =
			PreferenceManager.getDefaultSharedPreferences(getContext());


@@ 102,12 103,13 @@ public class SFTPDocumentsProvider extends DocumentsProvider {
			port = settings.getString("port", "22");
		}
		Log.v("SFTP", "connect " + host + ":" + port);
		connection = new Connection(host, Integer.parseInt(port));
		try {
			connection = new Connection(host, Integer.parseInt(port));
			connection.connect(null, 10000, 10000);
			if (!connection.authenticateWithPassword(settings.getString("username", ""),
				    settings.getString("passwd", ""))) {
				throwOrAddErrorExtra("Authentication failed.", cursor);
				connection.close();
				connection = null;
				return null;
			}


@@ 229,12 231,8 @@ public class SFTPDocumentsProvider extends DocumentsProvider {

	public Cursor queryRoots(String[] projection) {
		if (connection != null) {
			try {
				// XXX: why did we add ping?
				connection.ping();
				connection.close();
			} catch (IOException e) {
			}
			connection.close();
			connection = null;
		}
		MatrixCursor result =
			new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);