Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 163- DropBox tweaks to EasyImportManager #211

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 18 additions & 14 deletions bundles/net.tourbook/.classpath
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
<accessrules>
<accessrule kind="accessible" pattern="com/sun/net/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
<accessrules>
<accessrule kind="accessible" pattern="com/sun/net/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="org/eclipse/core/internal/databinding/conversion/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ public class EasyImportManager {

private static EasyImportManager _instance;

private final IDialogSettings _state = TourbookPlugin.getState(ID);

private EasyConfig _easyConfig;

private String _fileStoresHash;

private ReentrantLock STORE_LOCK = new ReentrantLock();

public static EasyImportManager getInstance() {

if (_instance == null) {
Expand All @@ -150,6 +142,15 @@ public static EasyImportManager getInstance() {
return _instance;
}

private final IDialogSettings _state = TourbookPlugin.getState(ID);

private EasyConfig _easyConfig;

private String _fileStoresHash;

private ReentrantLock STORE_LOCK = new ReentrantLock();


/**
* @param isForceRetrieveFiles
* When <code>true</code> files will be retrieved even when the stores have not
Expand All @@ -160,7 +161,7 @@ public static EasyImportManager getInstance() {
* {@link ImportConfig#notImportedFiles} contains the files which are available in the
* device folder but not available in the tour database.
*/
public DeviceImportState checkImportedFiles(final boolean isForceRetrieveFiles) {
public DeviceImportState checkImportedFiles(final boolean isForceRetrieveFiles) throws InterruptedException {

final DeviceImportState returnState = new DeviceImportState();

Expand Down Expand Up @@ -327,7 +328,7 @@ public EasyConfig getEasyConfig() {

/**
*/
private void getImportFiles(final Iterable<FileStore> fileStores) {
private void getImportFiles(final Iterable<FileStore> fileStores) throws InterruptedException {

final ArrayList<OSFile> movedFiles = new ArrayList<>();
final ArrayList<OSFile> notImportedFiles = new ArrayList<>();
Expand Down Expand Up @@ -412,7 +413,21 @@ private void getImportFiles(final Iterable<FileStore> fileStores) {
/*
* Get files which are not yet imported
*/

// Wrap in lock because of DB exception risk
// Thread can be interrupted before getting the lock, but not while in
// critical section. Watch for interrupt() or folderWatcher.close() !

RawDataView.THREAD_WATCHER_LOCK.lock();

if (Thread.currentThread().isInterrupted()) {
RawDataView.THREAD_WATCHER_LOCK.unlock();
Thread.currentThread().interrupt();
throw new InterruptedException();
}

final HashSet<String> dbFileNames = getDbFileNames(availableFiles);
RawDataView.THREAD_WATCHER_LOCK.unlock();

for (final OSFile deviceFile : availableFiles) {
if (dbFileNames.contains(deviceFile.getFileName()) == false) {
Expand All @@ -437,7 +452,7 @@ public int compare(final OSFile file1, final OSFile file2) {

private List<OSFile> getOSFiles(final String folder,
final String globFilePattern,
final Iterable<FileStore> fileStores) {
final Iterable<FileStore> fileStores) throws InterruptedException {

final List<OSFile> osFiles = new ArrayList<>();

Expand All @@ -452,9 +467,20 @@ private List<OSFile> getOSFiles(final String folder,
globPattern = ImportConfig.DEVICE_FILES_DEFAULT;
}

if (Thread.interrupted()) {
Thread.currentThread().interrupt();
throw new InterruptedException();
}

try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(validPath, globPattern)) {

for (final Path path : directoryStream) {

if (Thread.interrupted()) {
Thread.currentThread().interrupt();
throw new InterruptedException();
}

try {

final BasicFileAttributeView fileAttributesView = Files.getFileAttributeView(
Expand Down