mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 17:45:57 +08:00
Write to a temporary file before renaming with the final name. #1844
This commit is contained in:
parent
fbfd47b235
commit
2c11dd768a
@ -393,13 +393,16 @@ sub write_gcode {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($file) = @_;
|
my ($file) = @_;
|
||||||
|
|
||||||
|
my $tempfile;
|
||||||
|
|
||||||
# open output gcode file if we weren't supplied a file-handle
|
# open output gcode file if we weren't supplied a file-handle
|
||||||
my $fh;
|
my $fh;
|
||||||
if (ref $file eq 'IO::Scalar') {
|
if (ref $file eq 'IO::Scalar') {
|
||||||
$fh = $file;
|
$fh = $file;
|
||||||
} else {
|
} else {
|
||||||
Slic3r::open(\$fh, ">", $file)
|
$tempfile = "$file.tmp";
|
||||||
or die "Failed to open $file for writing\n";
|
Slic3r::open(\$fh, ">", $tempfile)
|
||||||
|
or die "Failed to open $tempfile for writing\n";
|
||||||
|
|
||||||
# enable UTF-8 output since user might have entered Unicode characters in fields like notes
|
# enable UTF-8 output since user might have entered Unicode characters in fields like notes
|
||||||
binmode $fh, ':utf8';
|
binmode $fh, ':utf8';
|
||||||
@ -413,6 +416,10 @@ sub write_gcode {
|
|||||||
|
|
||||||
# close our gcode file
|
# close our gcode file
|
||||||
close $fh;
|
close $fh;
|
||||||
|
|
||||||
|
if ($tempfile) {
|
||||||
|
rename $tempfile, $file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# this method will return the supplied input file path after expanding its
|
# this method will return the supplied input file path after expanding its
|
||||||
|
Loading…
x
Reference in New Issue
Block a user