Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix issue with file unlinking
[simgrid.git] / src / plugins / file_system / s4u_FileSystem.cpp
index 67e7ffd..6b63130 100644 (file)
@@ -17,7 +17,7 @@
 #include <fstream>
 #include <numeric>
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file, "S4U files");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_file, s4u, "S4U files");
 int sg_storage_max_file_descriptors = 1024;
 
 namespace simgrid {
@@ -26,10 +26,11 @@ simgrid::xbt::Extension<Disk, FileSystemDiskExt> FileSystemDiskExt::EXTENSION_ID
 simgrid::xbt::Extension<Storage, FileSystemStorageExt> FileSystemStorageExt::EXTENSION_ID;
 simgrid::xbt::Extension<Host, FileDescriptorHostExt> FileDescriptorHostExt::EXTENSION_ID;
 
-File::File(const std::string& fullpath, void* userdata) : File(fullpath, Host::current(), userdata){};
+File::File(const std::string& fullpath, void* userdata) : File(fullpath, Host::current(), userdata){}
 
-File::File(const std::string& fullpath, sg_host_t host, void* userdata) : fullpath_(fullpath), userdata_(userdata)
+File::File(const std::string& fullpath, sg_host_t host, void* userdata) : fullpath_(fullpath)
 {
+  this->set_data(userdata);
   // this cannot fail because we get a xbt_die if the mountpoint does not exist
   if (not host->get_mounted_storages().empty()) {
     Storage* st                  = nullptr;
@@ -205,7 +206,7 @@ sg_size_t File::write(sg_size_t size, int write_inside)
     if (sg_storage_get_size_used(local_storage_) >= sg_storage_get_size(local_storage_))
       return 0;
     if (write_inside == 0) {
-      /* Substract the part of the file that might disappear from the used sized on the storage element */
+      /* Subtract the part of the file that might disappear from the used sized on the storage element */
       local_storage_->extension<FileSystemStorageExt>()->decr_used_size(size_ - current_position_);
       write_size = local_storage_->write(size);
       local_storage_->extension<FileSystemStorageExt>()->incr_used_size(write_size);
@@ -230,7 +231,7 @@ sg_size_t File::write(sg_size_t size, int write_inside)
     if (sg_disk_get_size_used(local_disk_) >= sg_disk_get_size(local_disk_))
       return 0;
     if (write_inside == 0) {
-      /* Substract the part of the file that might disappear from the used sized on the storage element */
+      /* Subtract the part of the file that might disappear from the used sized on the storage element */
       local_disk_->extension<FileSystemDiskExt>()->decr_used_size(size_ - current_position_);
       write_size = local_disk_->write(size);
       local_disk_->extension<FileSystemDiskExt>()->incr_used_size(write_size);
@@ -335,7 +336,7 @@ int File::unlink()
       local_disk_->extension<FileSystemDiskExt>()->decr_used_size(size_);
 
     // Remove the file from storage
-    content->erase(fullpath_);
+    content->erase(path_);
 
     return 0;
   }
@@ -640,12 +641,12 @@ void sg_file_dump(sg_file_t fd)
 
 void* sg_file_get_data(sg_file_t fd)
 {
-  return fd->get_userdata();
+  return fd->get_data();
 }
 
 void sg_file_set_data(sg_file_t fd, void* data)
 {
-  fd->set_userdata(data);
+  fd->set_data(data);
 }
 
 /**
@@ -747,7 +748,7 @@ xbt_dict_t sg_storage_get_content(sg_storage_t storage)
   for (auto const& entry : *content) {
     sg_size_t* psize = new sg_size_t;
     *psize           = entry.second;
-    xbt_dict_set(content_as_dict, entry.first.c_str(), psize, nullptr);
+    xbt_dict_set(content_as_dict, entry.first.c_str(), psize);
   }
   return content_as_dict;
 }
@@ -757,7 +758,7 @@ xbt_dict_t sg_host_get_storage_content(sg_host_t host)
   xbt_assert((host != nullptr), "Invalid parameters");
   xbt_dict_t contents = xbt_dict_new_homogeneous(nullptr);
   for (auto const& elm : host->get_mounted_storages())
-    xbt_dict_set(contents, elm.first.c_str(), sg_storage_get_content(elm.second), nullptr);
+    xbt_dict_set(contents, elm.first.c_str(), sg_storage_get_content(elm.second));
 
   return contents;
 }