Просмотр исходного кода

Ensure the target file exists in write_data

Creating automatically the target file is valuable for testing
although it can hide issues in case the target device file is
missing in production, hence the removal.
Alessandro Pilotti 8 лет назад
Родитель
Сommit
c8b640a0eb
1 измененных файлов с 2 добавлено и 8 удалено
  1. 2 8
      coriolis/resources/write_data.c

+ 2 - 8
coriolis/resources/write_data.c

@@ -123,15 +123,9 @@ int handle_msg(FILE* input_stream)
     uint64_t offset = *((uint64_t*)data);
     data += sizeof(uint64_t);
 
-    // Create an empty file in case it does not exist
-    FILE* f = fopen(path, "ab+");
-    if (!f)
-        return ERR_OPEN_FILE;
-    if (fclose(f))
-        return ERR_IO_CLOSE;
-
     // Use rb+ to allow fseek when writing
-    f = fopen(path, "rb+");
+    // File must exist
+    FILE* f = fopen(path, "rb+");
     if (!f)
         return ERR_OPEN_FILE;
     if (fseek(f, (long)offset, SEEK_SET))