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

#26: Check for note existence before saving #29

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

tuancoltech
Copy link
Collaborator

Check for note existence before saving to avoid crash: #26

@tuancoltech tuancoltech self-assigned this Nov 10, 2023
@tuancoltech tuancoltech added the bug Something isn't working label Nov 10, 2023
@kirillt kirillt changed the title [bug] Check for note existence before saving to avoid crash. #26: Check for note existence before saving Nov 15, 2023
@@ -88,13 +91,19 @@ class TextNotesRepoImpl @Inject constructor(): TextNotesRepo {
persistNoteProperties(resourceId = id, noteTitle = note.content.title)

val resourcePath = root.resolve("$id.$NOTE_EXT")
val isDestinationExisting = File(resourcePath.toUri()).exists()
Copy link
Member

Choose a reason for hiding this comment

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

Do we really have to convert path to Uri and use File instance?

Copy link
Member

Choose a reason for hiding this comment

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

@tuancoltech is it realistic amount of work for this PR to wire index update flow from arklib-android into Memo? This should be the right way to establish awareness of paths in the folder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ShubertMunthali Oh yes, you're right :)
I updated that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kirillt I haven't got what that index update flow actually does for the Memo app.
Do you have an example (e.g, a commit hash) which does the same to other app?

Copy link
Member

Choose a reason for hiding this comment

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

@tuancoltech yes, in Navigator: https://github.com/ARK-Builders/ARK-Navigator/blob/main/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/ResourcesPresenter.kt

So the idea is that arklib handles all indexing and we can update the index using updateAll or updateOne which result in updates coming via the flow to the consumer. Ideally, the handling of all resources should be done reactive.

Copy link
Member

Choose a reason for hiding this comment

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

It should be considered as refactoring at this moment, the PR serves different purpose. But this async handling of updates would remove necessity to manually check exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kirillt That's cool. Yes, I took note of this and will look into the indexing part.
Thanks for the explanation!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By the way, I'm just curious how the indexing handles the existing file when creating duplicated file? What is its resolution strategy? Rename?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that's tough question at the moment. We need to improve arklib regarding duplicates and hash collisions. Basically, in rare cases when several resources map into same id, we just take only one resource, ignore the others. All metadata linked to the id points to all the collided resources though. We need to solve this: ARK-Builders/arklib#58

Exact duplicates always have same id, but I don't think it's a problem in this case. Because user cares about the content not the location, that's the idea of our project. Tricky situation is when duplicates come from different folders, but this is relevant only to Navigator with its aggregated mode.

@@ -88,13 +91,19 @@ class TextNotesRepoImpl @Inject constructor(): TextNotesRepo {
persistNoteProperties(resourceId = id, noteTitle = note.content.title)

val resourcePath = root.resolve("$id.$NOTE_EXT")
val isDestinationExisting = File(resourcePath.toUri()).exists()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val isDestinationExisting = File(resourcePath.toUri()).exists()

@@ -88,13 +91,19 @@ class TextNotesRepoImpl @Inject constructor(): TextNotesRepo {
persistNoteProperties(resourceId = id, noteTitle = note.content.title)

val resourcePath = root.resolve("$id.$NOTE_EXT")
val isDestinationExisting = File(resourcePath.toUri()).exists()
if (isDestinationExisting) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (isDestinationExisting) {
if (resourcePath.exists()) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants