bcftools icon indicating copy to clipboard operation
bcftools copied to clipboard

bcftools reheader Incomplete File if Output Same as Input

Open DarioS opened this issue 1 year ago • 1 comments

It sounds like it should be possible to modify file in-place:

bcftools reheader [OPTIONS] file.vcf.gz Modify header of VCF/BCF files, change sample names.

However, if -o path is same as input file path, the result is a corrupted file. Why not an error message or work as expected?

DarioS avatar Mar 26 '24 05:03 DarioS

I am reluctant to add checks like that, certain awareness is required from users when working with command line tools.

Few notes if such check should be added:

  • this affects and would be added to all bcftools commands
  • realpath() would have to be used to prevent common variations (eg ./file.bcf vs file.bcf) or symlinks
  • this would still not catch hard links
  • this would still not catch cases where multiple commands are piped together
  • probably best is to check for the existence of output file. However, this breaks backward compatibility and will not be liked by those who want to overwrite existing files without being asked

So although seemingly simple, it's not an easy decision to make.

pd3 avatar Apr 27 '24 10:04 pd3