Skip to content

Commit cc12344

Browse files
committed
File Stream API now unlinks before open with O_EXCL
The File Stream API now unlinks the destination file (i.e., `<FILENAME>.cfnew`) before opening it with the `O_EXCL` flag. Previously the agent would fail if the destination file already exists. Fortunately, the File Stream API unlinks this file afterwards, both on success and error, causing the agent to recover. Both the `cf-net get <FILENAME>` command and the `copy_from` attribute were affected. Ticket: None Changelog: Commit Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent 99a802a commit cc12344

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

libcfnet/file_stream.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ static bool RecvDelta(
853853
char in_buf[PROTOCOL_MESSAGE_SIZE * 2], out_buf[PROTOCOL_MESSAGE_SIZE];
854854

855855
/* Open/create the destination file */
856+
unlink(dest);
856857
int new = safe_open_create_perms(
857858
dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | O_BINARY, perms);
858859
if (new == -1)

0 commit comments

Comments
 (0)