-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,506 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package muon.misc; | ||
|
||
import muon.util.AppUtils; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class CancellationToken implements AutoCloseable { | ||
private CountDownLatch countDownLatch = new CountDownLatch(1); | ||
private AtomicBoolean cancellationRequested = new AtomicBoolean(false); | ||
private AtomicBoolean closed = new AtomicBoolean(false); | ||
|
||
public void await() { | ||
AppUtils.await(countDownLatch); | ||
} | ||
|
||
public void requestCancellation() { | ||
if (closed.get()) { | ||
return; | ||
} | ||
cancellationRequested.set(true); | ||
countDownLatch.countDown(); | ||
} | ||
|
||
public boolean isCancellationRequested() { | ||
return cancellationRequested.get(); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
if (closed.get()) { | ||
return; | ||
} | ||
if (countDownLatch.getCount() == 1) { | ||
countDownLatch.countDown(); | ||
} | ||
closed.set(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* | ||
*/ | ||
package muon.misc; | ||
|
||
import net.schmizz.sshj.sftp.*; | ||
import net.schmizz.sshj.sftp.Response.StatusCode; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author subhro | ||
*/ | ||
public class ExtendedRemoteDirectory extends RemoteDirectory { | ||
|
||
/** | ||
* @param requester | ||
* @param path | ||
* @param handle | ||
*/ | ||
public ExtendedRemoteDirectory(SFTPEngine requester, String path, | ||
byte[] handle) { | ||
super(requester, path, handle); | ||
} | ||
|
||
public List<RemoteResourceInfoWrapper> scanExtended( | ||
CancellationToken cancellationToken) throws IOException { | ||
List<RemoteResourceInfoWrapper> rri = new ArrayList<>(); | ||
// TODO: Remove GOTO! | ||
loop: | ||
for (; ; ) { | ||
if (cancellationToken.isCancellationRequested()) { | ||
throw new IOException("Operation cancelled"); | ||
} | ||
final Response res = requester | ||
.request(newRequest(PacketType.READDIR)) | ||
.retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS); | ||
switch (res.getType()) { | ||
|
||
case NAME: | ||
final int count = res.readUInt32AsInt(); | ||
for (int i = 0; i < count; i++) { | ||
final String name = res.readString( | ||
requester.getSubsystem().getRemoteCharset()); | ||
final String longName = res.readString(); | ||
|
||
final FileAttributes attrs = res.readFileAttributes(); | ||
final PathComponents comps = requester.getPathHelper() | ||
.getComponents(path, name); | ||
final RemoteResourceInfo inf = new RemoteResourceInfo(comps, | ||
attrs); | ||
final RemoteResourceInfoWrapper wri = new RemoteResourceInfoWrapper( | ||
inf, longName); | ||
rri.add(wri); | ||
} | ||
break; | ||
|
||
case STATUS: | ||
res.ensureStatusIs(StatusCode.EOF); | ||
break loop; | ||
|
||
default: | ||
throw new SFTPException("Unexpected packet: " + res.getType()); | ||
} | ||
} | ||
return rri; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/muon/misc/RemoteResourceInfoWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* | ||
*/ | ||
package muon.misc; | ||
|
||
import net.schmizz.sshj.sftp.RemoteResourceInfo; | ||
|
||
/** | ||
* @author subhro | ||
* | ||
*/ | ||
public class RemoteResourceInfoWrapper { | ||
/** | ||
* @param info | ||
* @param longPath | ||
*/ | ||
public RemoteResourceInfoWrapper(RemoteResourceInfo info, String longPath) { | ||
super(); | ||
this.info = info; | ||
this.longPath = longPath; | ||
} | ||
|
||
private RemoteResourceInfo info; | ||
private String longPath; | ||
|
||
/** | ||
* @return the info | ||
*/ | ||
public RemoteResourceInfo getInfo() { | ||
return info; | ||
} | ||
|
||
/** | ||
* @param info the info to set | ||
*/ | ||
public void setInfo(RemoteResourceInfo info) { | ||
this.info = info; | ||
} | ||
|
||
/** | ||
* @return the longPath | ||
*/ | ||
public String getLongPath() { | ||
return longPath; | ||
} | ||
|
||
/** | ||
* @param longPath the longPath to set | ||
*/ | ||
public void setLongPath(String longPath) { | ||
this.longPath = longPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.