Skip to content

Commit

Permalink
File Stream API now unlinks before open with O_EXCL
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
larsewi committed Dec 19, 2024
1 parent 99a802a commit cc12344
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions libcfnet/file_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ static bool RecvDelta(
char in_buf[PROTOCOL_MESSAGE_SIZE * 2], out_buf[PROTOCOL_MESSAGE_SIZE];

/* Open/create the destination file */
unlink(dest);
int new = safe_open_create_perms(
dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | O_BINARY, perms);
if (new == -1)
Expand Down

0 comments on commit cc12344

Please sign in to comment.