@@ -31,7 +31,13 @@ impl crate::storage::common::Storage for BasicStorage {
3131 let key_path_created = format ! ( "{}::{}@{}" , user_id, key_name, timestamp) ;
3232 let user_id_key_name = format ! ( "{}::{}" , user_id, key_name) ;
3333 debug ! ( "{}" , user_id_key_name) ;
34- if map. contains_key ( & user_id_key_name) {
34+ if map. contains_key ( & user_id_key_name)
35+ && map. contains_key ( & format ! (
36+ "{}@{}" ,
37+ user_id_key_name,
38+ String :: from_utf8( map. get( & user_id_key_name) . unwrap( ) . to_vec( ) ) . unwrap( )
39+ ) )
40+ {
3541 return Err ( format ! ( "Key name already exists: {}" , user_id_key_name) ) ;
3642 }
3743 map. insert ( key_path_created. clone ( ) , value. to_vec ( ) ) ;
@@ -65,7 +71,7 @@ impl crate::storage::common::Storage for BasicStorage {
6571 let value = map. get ( key_path) ;
6672 match value {
6773 Some ( v) => result. insert ( key_path. clone ( ) , v. clone ( ) ) ,
68- None => return Err ( format ! ( "Key not found: {}" , key_path) ) ,
74+ None => return Err ( format ! ( "Key path not found: {}" , key_path) ) ,
6975 } ;
7076 }
7177 Ok ( result)
@@ -90,7 +96,7 @@ impl crate::storage::common::Storage for BasicStorage {
9096 let value = map. get ( & key_path) ;
9197 match value {
9298 Some ( v) => result. insert ( key_path, v. clone ( ) ) ,
93- None => return Err ( format ! ( "Key path not found : {}" , key_path) ) ,
99+ None => return Err ( format ! ( "Entry have been deleted : {}" , key_path) ) ,
94100 } ;
95101 }
96102 Ok ( result)
@@ -152,7 +158,17 @@ impl crate::storage::common::Storage for BasicStorage {
152158 let timestamp = Utc :: now ( ) . timestamp ( ) ;
153159 let mut map = self . map . lock ( ) . await ;
154160 let user_id_key_name = format ! ( "{}::{}" , user_id, key_name) ;
155- map. insert ( user_id_key_name, timestamp. to_string ( ) . into_bytes ( ) ) ;
156- Ok ( format ! ( "{}::{}@{}" , user_id, key_name, timestamp) )
161+ if map. contains_key ( & user_id_key_name)
162+ && map. contains_key ( & format ! (
163+ "{}@{}" ,
164+ user_id_key_name,
165+ String :: from_utf8( map. get( & user_id_key_name) . unwrap( ) . to_vec( ) ) . unwrap( )
166+ ) )
167+ {
168+ map. insert ( user_id_key_name, timestamp. to_string ( ) . into_bytes ( ) ) ;
169+ Ok ( format ! ( "{}::{}@{}" , user_id, key_name, timestamp) )
170+ } else {
171+ Err ( format ! ( "Key name not found: {}" , key_name) )
172+ }
157173 }
158174}
0 commit comments