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 request] Is it possible to support some kind(s) portable mode? #297

Closed
PM2p5 opened this issue Aug 19, 2023 · 11 comments
Closed

[Feature request] Is it possible to support some kind(s) portable mode? #297

PM2p5 opened this issue Aug 19, 2023 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@PM2p5
Copy link

PM2p5 commented Aug 19, 2023

Is it possible to support a portable mode? I think it will be much concise and easy to use if it does!

I have concluded 3 possible options:

  1. By specify the location of the the core db file ".cotp\db.cotp", to a user specified place. The command switch would be:
    cotp db --path 'path/to/the/db.cotp'.

  2. Add a portable switch, and load the db in the same folder:
    cotp --portable

  3. Check if a blank file named 'portable_mode' exists, if yes, load the db in the same folder.

Thanks in advance!

@replydev
Copy link
Owner

replydev commented Aug 19, 2023

I think that the most clean way to check if db.cotp file exists in the same directory as the binary executable.

Currently, this is the behaviour only if the artifact is compiled in debug mode, as I use preprocess macros.

This could be the occation to delete this debug / release dispatch and just use db.cotp if found.

Finally, we could fallback to default folder if the existing db.cotp file is corrupted.

Let me know what you think about, thank you!

@replydev replydev self-assigned this Aug 19, 2023
@replydev replydev added the enhancement New feature or request label Aug 19, 2023
@PM2p5
Copy link
Author

PM2p5 commented Aug 21, 2023

I think that the most clean way to check if db.cotp file exists in the same directory as the binary executable.

Currently, this is the behaviour only if the artifact is compiled in debug mode, as I use preprocess macros.

This could be the occation to delete this debug / release dispatch and just use db.cotp if found.

Finally, we could fallback to default folder if the existing db.cotp file is corrupted.

Let me know what you think about, thank you!

Hello, replydev!

Your way to deal the portable mode is more concise!

Here is my understanding of the new behavior, correct me if I was wrong: The (new) App will first check it's working directory, if there is a db file, then load it. If the db does not exist or has some kind of error in it, load another db in the old place the App used to. (eg: %userprofile% folder on Windows, the ~ folder on Linux).

If the App works like this, it will be great! Many many thanks for the amazing work!!

Have a great day!!!

@PM2p5
Copy link
Author

PM2p5 commented Aug 21, 2023

Here is another detail need to be taken into consideration if the App works as described above.

What if both DB corrupted(the one in the working directory and another one in the user's home folder)? Will there be some kind of warnings and prompts to allow user to create a new db? If the App is about to create a new db, will it ask the user to clarify which DB to create?

@replydev
Copy link
Owner

Right now it will just display an error message. I would not create confusing behaviour of overwriting or deleting the file accidentally.

@PM2p5
Copy link
Author

PM2p5 commented Aug 22, 2023

Right now it will just display an error message. I would not create confusing behaviour of overwriting or deleting the file accidentally.

Yeah, that sounds good!
Let users to handle this corner situation is good enough for the potential target users, especially consider this is a TUI based App.

@replydev
Copy link
Owner

replydev commented Sep 7, 2023

@PM2p5 you can use the environment variable COTP_DB_PATH to specify a custom database file path. It is already implemented :).

Just took a look to the code today after long holidays.

@PM2p5
Copy link
Author

PM2p5 commented Sep 12, 2023

@PM2p5 you can use the environment variable COTP_DB_PATH to specify a custom database file path. It is already implemented :).

Just took a look to the code today after long holidays.

Hello, replydev!

I've tested the variable of COTP_DB_PATH on Windows, it's working well!

Testing method: Set an user variable of COTP_DB_PATH on Windows, and tested following values:

Succeed:

C:\Users\Alice\Desktop\db.cotp
%userprofile%\Desktop\.cotp\db.cotp

Failed with the message:
Cannot decrypt existing database: Error during file reading: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }

C:\Users\Alice\Desktop\
%userprofile%\Desktop\.cotp\
C:/Users/Alice/Desktop/
C:/Users/Alice/Desktop/db.cotp
%userprofile%/Desktop/db.cotp
%userprofile%/Desktop/.cotp/db.cotp

Now the only thing left here is to design the portable mode, allow it to work together with the COTP_DB_PATH and the default path of ~/.cotp/db.cotp

@replydev
Copy link
Owner

Could you please elaborate:

Now the only thing left here is to design the portable mode, allow it to work together with the COTP_DB_PATH and the default path of ~/.cotp/db.cotp

@PM2p5
Copy link
Author

PM2p5 commented Sep 16, 2023

Could you please elaborate:

Now the only thing left here is to design the portable mode, allow it to work together with the COTP_DB_PATH and the default path of ~/.cotp/db.cotp

Hi, replydev!

The portable mode in my opinion could be like this:

1st, check the existence of the db.cotp in the App folder(working directory), if yes, check and load the db!
2nd, if the db.cotp doesn't exist, then it's not the portable mode! The App should work as old days when it didn't support the portable mode.
3rd, if it's not the portable mode, check the COTP_DB_PATH variable, check and load the db!
4th, if the COTP_DB_PATH doesn't exist, check and load the db from the default path of ~/.cotp/db.cotp.

I've peeked the branch of portable mode from here https://github.com/replydev/cotp/tree/feat/portable_mode
The code form your commit of 2079ea6

pub fn is_portable_mode() -> bool {
    PathBuf::from("db.cotp").exists()
}

This seems to be the same idea as I wrote in the 1st and 2nd steps.
After some quick tests with the debug artifacts, the current behavior is to check the COTP_DB_PATH variable 1st, then check the db.cotp in the App folder(working directory), and finally the default path of ~/.cotp/db.cotp. Which seems okay!

Tell me something about your idea!

@replydev
Copy link
Owner

Ok, i see that it's more or less already implemented. I will push a PR.

@replydev
Copy link
Owner

Hi @PM2p5, I merged #325.

Now we support db.cotp file in working directory.
I think we can consider this issued closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants