Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fixing file remane. psize is freed by dict_remove, can't be used in
[simgrid.git] / src / surf / storage.c
index 0f28e4f..a5a59ae 100644 (file)
@@ -215,7 +215,7 @@ static xbt_dict_t storage_get_content(void *storage)
   char *file;
   sg_storage_size_t *psize;
 
-  xbt_dict_foreach(((storage_t)st)->content, cursor, file, psize){
+  xbt_dict_foreach(((storage_t)storage_resource)->content, cursor, file, psize){
     xbt_dict_set(content_dict,file,psize,NULL);
   }
   return content_dict;
@@ -226,6 +226,24 @@ static sg_storage_size_t storage_get_size(void *storage){
   return ((storage_t)storage_resource)->size;
 }
 
+static void storage_file_rename(void *storage, const char *src, const char *dest)
+{
+  void *storage_resource = surf_storage_resource_priv(storage);
+
+  sg_storage_size_t *psize, *new_psize;
+  psize = (sg_storage_size_t*) xbt_dict_get_or_null(((storage_t)storage_resource)->content,src);
+  new_psize = xbt_new(sg_storage_size_t, 1);
+  *new_psize = *psize;
+  if (psize){// src file exists
+    xbt_dict_remove(((storage_t)storage_resource)->content, src);
+    xbt_dict_set(((storage_t)storage_resource)->content, dest, new_psize,NULL);
+    XBT_DEBUG("Change file name from %s to %s, size '%" PRIu64 "'",src, dest, *psize);
+  }
+  else
+    XBT_DEBUG("File %s doesn't exist",src);
+}
+
+
 static void* storage_create_resource(const char* id, const char* model,
     const char* type_id, const char* content_name, const char* content_type, xbt_dict_t properties){
   storage_t storage = NULL;
@@ -538,6 +556,7 @@ static void surf_storage_model_init_internal(void)
   surf_storage_model->extension.storage.get_properties = storage_get_properties;
   surf_storage_model->extension.storage.get_content = storage_get_content;
   surf_storage_model->extension.storage.get_size = storage_get_size;
+  surf_storage_model->extension.storage.rename = storage_file_rename;
   if (!storage_maxmin_system) {
     storage_maxmin_system = lmm_system_new(storage_selective_update);
   }