int r;
char* buffer = NULL;
+ size_t l = 0;
char* line = NULL;
size_t length = 0;
char* p = NULL;
if (r < 0)
goto ERROR;
+ // Store length of the buffer
+ l = r;
+
// Process the next line
break;
r = asprintf(&buffer, "%s%s", buffer, line);
if (r < 0)
goto ERROR;
+
+ // Store length of the buffer
+ l = r;
+
break;
}
}
// Go back to the beginning of the file
rewind(f);
+ // Truncate the existing content
+ r = ftruncate(fileno(f), 0);
+ if (r) {
+ ERROR(file->pakfire, "Could not truncate %s: %m\n", path);
+ r = -errno;
+ goto ERROR;
+ }
+
// Write back the buffer
if (buffer) {
- size_t bytes_written = fwrite(buffer, 1, strlen(buffer), f);
- if (bytes_written < length) {
+ size_t bytes_written = fwrite(buffer, 1, l, f);
+ if (bytes_written < l) {
ERROR(file->pakfire, "%s: Could not write the payload: %m\n", path);
r = -errno;
goto ERROR;