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

File Monitoring #107

Closed
wants to merge 2 commits into from
Closed

File Monitoring #107

wants to merge 2 commits into from

Conversation

mdrlzy
Copy link
Member

@mdrlzy mdrlzy commented Oct 15, 2021

No description provided.

@mdrlzy mdrlzy force-pushed the model-refactoring branch from 678d4e5 to 9a005f8 Compare October 20, 2021 03:52
@kirillt
Copy link
Member

kirillt commented Oct 24, 2021

@mdrlzy could you list issues which this PR solves?

@mdrlzy
Copy link
Member Author

mdrlzy commented Oct 26, 2021

Issues covered: #27 #76

@mdrlzy mdrlzy force-pushed the model-refactoring branch from 9a005f8 to 88c4f51 Compare October 29, 2021 09:46

class FSMonitoring(
val indexCache: IndexCache,
val tagsCache: TagsCache,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

class FSMonitoring(
val indexCache: IndexCache,
val tagsCache: TagsCache,
val appScope: CoroutineScope
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

}
}

private fun onDelete(root: Path, directory: Path, eventPath: Path) = appScope.launch(Dispatchers.Default) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directory is not unused

tagsCache.remove(id)
}

private fun onMovedFrom(root: Path, directory: Path, eventPath: Path) = appScope.launch(Dispatchers.Default) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directory is not unused

indexCache.onResourceDeleted(root, eventPath)
}

private fun onMovedTo(root: Path, directory: Path, eventPath: Path) = appScope.launch(Dispatchers.Default) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directory is not unused


class RecursiveDirectoryObserver(
private val fsMonitoring: FSMonitoring,
private val root: String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use strings to work with paths unless it's not impossible.
val root: Path

val parent: String = stack.pop()
directoryObservers.add(DirectoryObserver.create(this, parent))
val path = File(parent)
val files: Array<File> = path.listFiles() ?: continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use newer java.nio.file package.
Files.list(path)


override fun onEvent(event: Int, path: String?) {
val eventCode = event and ALL_EVENTS
val eventPath = path?.let { "$directory/$path" }
fun log(directory: String, event: Int, eventPath: String?) {
val eventName = provideEventName(event)
eventName?.let {
Timber.d("$eventName \n Directory: $directory \n Path: $eventPath")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use plain Log.d with filesystem tag?

@@ -22,6 +32,7 @@ class MainPresenter: MvpPresenter<MainView>() {

fun permsGranted() {
Log.d(MAIN, "creating Folders screen")
presenterScope.launch { indexingEngine.reindex() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reindexing all roots during start-up can take unnecessarily long time.

@kirillt kirillt closed this Oct 29, 2021
@kirillt kirillt deleted the model-refactoring branch October 29, 2021 14:36
@kirillt
Copy link
Member

kirillt commented Oct 29, 2021

Renamed branch into archive/27-file-monitoring since there are some useful bits.

@kirillt kirillt changed the title Model refactoring File Monitoring Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants