MatrixAI / Polykey

Polykey Core Library
https://polykey.com
GNU General Public License v3.0
30 stars 4 forks source link

Redesign vault clone name conflict handling #672

Open tegefaulkes opened 8 months ago

tegefaulkes commented 8 months ago

Specification

Currently this is handled very simply where we take the existing name and increment the number on it as vaultname-1 vaultname-2 etc etc. It does this until the name doesn't already exists and uses that for the name. Otherwise it hits 50 attempts and throws. The problem with this is that the hard coded limit is not ideal.

In my mind there are two alternatives. When cloning a vault and there is a name conflict it will just fail. You can specify a new name and if that conflicts it will also fail. It's pretty simple and gives the user the ability to specify the desired name.

Alternatively since the names are indexed, if the name is taken we can reverse iterate once using that name as the starting position. Then take that and append -copy to it.

Additional context

Related: #652

Tasks

  1. Determine a better alternative method for handling name conflicts when cloning.
  2. Implement this method.
tegefaulkes commented 8 months ago

The 2nd option still rubs me wrong. It's too easy to have weird edge cases. For example say we have the following.

  1. a vault named vault
  2. a vault named vaultOther
  3. we clone a remote vault called vault.

Can we not end up with the naming conflict resolved as vaultOther-copy?

CMCDragonkai commented 8 months ago

If you clone a vault vault and vault already exists, then you'd get vault-copy. If there was a vault-copy then it would be vault-copy-copy. I'm looking at something similar to Windows Explorer/Dropbox when they resolved this problem, we can just copy them.