@@ -66,17 +66,35 @@ impl FilesystemStore {
66
66
outer_lock. retain ( |_, v| Arc :: strong_count ( & v) > 1 ) ;
67
67
}
68
68
}
69
+
70
+ fn get_dest_dir_path ( & self , namespace : & str , sub_namespace : & str ) -> std:: io:: Result < PathBuf > {
71
+ let mut dest_dir_path = {
72
+ #[ cfg( target_os = "windows" ) ]
73
+ {
74
+ let data_dir = self . data_dir . clone ( ) ;
75
+ fs:: create_dir_all ( data_dir. clone ( ) ) ?;
76
+ fs:: canonicalize ( data_dir) ?
77
+ }
78
+ #[ cfg( not( target_os = "windows" ) ) ]
79
+ {
80
+ self . data_dir . clone ( )
81
+ }
82
+ } ;
83
+
84
+ dest_dir_path. push ( namespace) ;
85
+ if !sub_namespace. is_empty ( ) {
86
+ dest_dir_path. push ( sub_namespace) ;
87
+ }
88
+
89
+ Ok ( dest_dir_path)
90
+ }
69
91
}
70
92
71
93
impl KVStore for FilesystemStore {
72
94
fn read ( & self , namespace : & str , sub_namespace : & str , key : & str ) -> std:: io:: Result < Vec < u8 > > {
73
95
check_namespace_key_validity ( namespace, sub_namespace, Some ( key) , "read" ) ?;
74
96
75
- let mut dest_file_path = self . data_dir . clone ( ) ;
76
- dest_file_path. push ( namespace) ;
77
- if !sub_namespace. is_empty ( ) {
78
- dest_file_path. push ( sub_namespace) ;
79
- }
97
+ let mut dest_file_path = self . get_dest_dir_path ( namespace, sub_namespace) ?;
80
98
dest_file_path. push ( key) ;
81
99
82
100
let mut buf = Vec :: new ( ) ;
@@ -99,11 +117,7 @@ impl KVStore for FilesystemStore {
99
117
fn write ( & self , namespace : & str , sub_namespace : & str , key : & str , buf : & [ u8 ] ) -> std:: io:: Result < ( ) > {
100
118
check_namespace_key_validity ( namespace, sub_namespace, Some ( key) , "write" ) ?;
101
119
102
- let mut dest_file_path = self . data_dir . clone ( ) ;
103
- dest_file_path. push ( namespace) ;
104
- if !sub_namespace. is_empty ( ) {
105
- dest_file_path. push ( sub_namespace) ;
106
- }
120
+ let mut dest_file_path = self . get_dest_dir_path ( namespace, sub_namespace) ?;
107
121
dest_file_path. push ( key) ;
108
122
109
123
let parent_directory = dest_file_path
@@ -190,11 +204,7 @@ impl KVStore for FilesystemStore {
190
204
fn remove ( & self , namespace : & str , sub_namespace : & str , key : & str , lazy : bool ) -> std:: io:: Result < ( ) > {
191
205
check_namespace_key_validity ( namespace, sub_namespace, Some ( key) , "remove" ) ?;
192
206
193
- let mut dest_file_path = self . data_dir . clone ( ) ;
194
- dest_file_path. push ( namespace) ;
195
- if !sub_namespace. is_empty ( ) {
196
- dest_file_path. push ( sub_namespace) ;
197
- }
207
+ let mut dest_file_path = self . get_dest_dir_path ( namespace, sub_namespace) ?;
198
208
dest_file_path. push ( key) ;
199
209
200
210
if !dest_file_path. is_file ( ) {
@@ -283,12 +293,7 @@ impl KVStore for FilesystemStore {
283
293
fn list ( & self , namespace : & str , sub_namespace : & str ) -> std:: io:: Result < Vec < String > > {
284
294
check_namespace_key_validity ( namespace, sub_namespace, None , "list" ) ?;
285
295
286
- let mut prefixed_dest = self . data_dir . clone ( ) ;
287
- prefixed_dest. push ( namespace) ;
288
- if !sub_namespace. is_empty ( ) {
289
- prefixed_dest. push ( sub_namespace) ;
290
- }
291
-
296
+ let prefixed_dest = self . get_dest_dir_path ( namespace, sub_namespace) ?;
292
297
let mut keys = Vec :: new ( ) ;
293
298
294
299
if !Path :: new ( & prefixed_dest) . exists ( ) {
0 commit comments