11
11
#include "config-paths.h"
12
12
13
13
#include "utils/strutils.h"
14
+ #include "pathshash.h"
14
15
#include "dlite.h"
15
16
#include "dlite-macros.h"
16
17
#include "dlite-misc.h"
@@ -28,13 +29,13 @@ typedef PyObject *(*InstanceConverter)(DLiteInstance *inst);
28
29
29
30
/* Global state for this module */
30
31
typedef struct {
31
- FUPaths paths ; /* Python storage paths */
32
- int initialised ; /* Whether `paths` is initiated */
33
- int modified ; /* Whether `paths` is modified */
34
- PyObject * loaded_storages ; /* Cache with all loaded python storage plugins */
35
- char * * failed_paths ; /* NULL-terminated array of paths to storages
36
- that fail to load. */
37
- size_t failed_len ; /* Allocated length of `failed_paths`. */
32
+ FUPaths paths ; /* Python storage paths */
33
+ int initialised ; /* Whether `paths` is initiated */
34
+ unsigned char paths_hash [ 32 ] ; /* Sha3 hash of plugin paths */
35
+ PyObject * loaded_storages ; /* Cache with all loaded python storage plugins */
36
+ char * * failed_paths ; /* NULL-terminated array of paths to storages
37
+ that fail to load. */
38
+ size_t failed_len ; /* Allocated length of `failed_paths`. */
38
39
} PythonStorageGlobals ;
39
40
40
41
@@ -102,7 +103,6 @@ FUPaths *dlite_python_storage_paths(void)
102
103
if (s < 0 ) return dlite_err (1 , "error initialising dlite python storage "
103
104
"plugin dirs" ), NULL ;
104
105
g -> initialised = 1 ;
105
- g -> modified = 0 ;
106
106
107
107
/* Make sure that dlite DLLs are added to the library search path */
108
108
dlite_add_dll_path ();
@@ -119,7 +119,6 @@ void dlite_python_storage_paths_clear(void)
119
119
if (g -> initialised ) {
120
120
fu_paths_deinit (& g -> paths );
121
121
g -> initialised = 0 ;
122
- g -> modified = 0 ;
123
122
}
124
123
}
125
124
@@ -131,14 +130,9 @@ void dlite_python_storage_paths_clear(void)
131
130
*/
132
131
int dlite_python_storage_paths_insert (const char * path , int n )
133
132
{
134
- int stat ;
135
133
const FUPaths * paths ;
136
134
if (!(paths = dlite_python_storage_paths ())) return -1 ;
137
- if ((stat = fu_paths_insert ((FUPaths * )paths , path , n ))) {
138
- PythonStorageGlobals * g = get_globals ();
139
- g -> modified = 1 ;
140
- }
141
- return stat ;
135
+ return fu_paths_insert ((FUPaths * )paths , path , n );
142
136
}
143
137
144
138
/*
@@ -147,14 +141,9 @@ int dlite_python_storage_paths_insert(const char *path, int n)
147
141
*/
148
142
int dlite_python_storage_paths_append (const char * path )
149
143
{
150
- int stat ;
151
144
const FUPaths * paths ;
152
145
if (!(paths = dlite_python_storage_paths ())) return -1 ;
153
- if ((stat = fu_paths_append ((FUPaths * )paths , path ))) {
154
- PythonStorageGlobals * g = get_globals ();
155
- g -> modified = 1 ;
156
- }
157
- return stat ;
146
+ return fu_paths_append ((FUPaths * )paths , path );
158
147
}
159
148
160
149
/*
@@ -163,14 +152,9 @@ int dlite_python_storage_paths_append(const char *path)
163
152
*/
164
153
int dlite_python_storage_paths_remove_index (int index )
165
154
{
166
- int stat ;
167
155
const FUPaths * paths ;
168
156
if (!(paths = dlite_python_storage_paths ())) return -1 ;
169
- if ((stat = fu_paths_remove_index ((FUPaths * )paths , index ))) {
170
- PythonStorageGlobals * g = get_globals ();
171
- g -> modified = 1 ;
172
- }
173
- return stat ;
157
+ return fu_paths_remove_index ((FUPaths * )paths , index );
174
158
}
175
159
176
160
/*
@@ -194,15 +178,17 @@ const char **dlite_python_storage_paths_get(void)
194
178
void * dlite_python_storage_load (void )
195
179
{
196
180
PyObject * storagebase ;
181
+ unsigned char hash [32 ];
182
+ const FUPaths * paths ;
197
183
PythonStorageGlobals * g = get_globals ();
198
184
199
185
if (!(storagebase = dlite_python_storage_base ())) return NULL ;
186
+ if (!(paths = dlite_python_storage_paths ())) return NULL ;
187
+ if (pathshash (hash , sizeof (hash ), paths , "*.py" )) return NULL ;
200
188
201
- if (!g -> loaded_storages || g -> modified ) {
202
- const FUPaths * paths ;
189
+ if (!g -> loaded_storages || memcmp ( g -> paths_hash , hash , sizeof ( hash )) != 0 ) {
190
+ memcpy ( g -> paths_hash , hash , sizeof ( hash )) ;
203
191
if (g -> loaded_storages ) dlite_python_storage_unload ();
204
- if (!(paths = dlite_python_storage_paths ())) return NULL ;
205
-
206
192
g -> loaded_storages = dlite_pyembed_load_plugins ((FUPaths * )paths ,
207
193
storagebase ,
208
194
& g -> failed_paths ,
0 commit comments