[pbs-devel] [PATCH backup] use truncate whenever we create files
Maximiliano Sandoval
m.sandoval at proxmox.com
Wed Jan 15 16:20:09 CET 2025
Fabian Grünbichler <f.gruenbichler at proxmox.com> writes:
>> diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs
>> index cfbd8d51..b3e7d535 100644
>> --- a/pbs-client/src/pxar/extract.rs
>> +++ b/pbs-client/src/pxar/extract.rs
>> @@ -134,6 +134,7 @@ where
>> if let Some(entry) = prelude {
>> let mut prelude_file = OpenOptions::new()
>> .create(true)
>> + .truncate(true)
>> .write(true)
>> .open(path)
>> .with_context(|| format!("error creating prelude file '{path:?}'"))?;
>
> this one should honor the overwrite flag and not truncate
> unconditionally (see below)
Sorry I am not following, the two diffs bellow use the same flags
(except that they also add `read(true)`).
>> diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs
>> index 93a6053b..2cc1baab 100644
>> --- a/src/api2/tape/restore.rs
>> +++ b/src/api2/tape/restore.rs
>> @@ -1711,6 +1711,7 @@ fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
>> let mut tmpfile = std::fs::OpenOptions::new()
>> .write(true)
>> .create(true)
>> + .truncate(true)
>
> this is okay, provided the tape code has locked the snapshot path this
> is operating in (seems to be the case after a quick glance - @Dominik?)
>
>> .read(true)
>> .open(&tmp_path)
>> .map_err(|err| format_err!("restore {:?} failed - {}", tmp_path, err))?;
>> diff --git a/src/server/sync.rs b/src/server/sync.rs
>> index 0bd7a7a8..04654c28 100644
>> --- a/src/server/sync.rs
>> +++ b/src/server/sync.rs
>> @@ -159,6 +159,7 @@ impl SyncSourceReader for RemoteSourceReader {
>> let tmpfile = std::fs::OpenOptions::new()
>> .write(true)
>> .create(true)
>> + .truncate(true)
>
> this is in a locked context, so should be okay as well..
>
>> .read(true)
>> .open(&tmp_path)?;
>>
>> --
>> 2.39.5
>>
>>
>>
>> _______________________________________________
>> pbs-devel mailing list
>> pbs-devel at lists.proxmox.com
>> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>>
>>
>>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
More information about the pbs-devel
mailing list