mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 20:51:12 -06:00 
			
		
		
		
	Write to a temporary file before renaming with the final name. #1844
This commit is contained in:
		
							parent
							
								
									6b1a72aac9
								
							
						
					
					
						commit
						bbd63616b1
					
				
					 1 changed files with 9 additions and 2 deletions
				
			
		|  | @ -394,13 +394,16 @@ sub write_gcode { | |||
|     my $self = shift; | ||||
|     my ($file) = @_; | ||||
|      | ||||
|     my $tempfile; | ||||
|      | ||||
|     # open output gcode file if we weren't supplied a file-handle | ||||
|     my $fh; | ||||
|     if (ref $file eq 'IO::Scalar') { | ||||
|         $fh = $file; | ||||
|     } else { | ||||
|         Slic3r::open(\$fh, ">", $file) | ||||
|             or die "Failed to open $file for writing\n"; | ||||
|         $tempfile = "$file.tmp"; | ||||
|         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 | ||||
|         binmode $fh, ':utf8'; | ||||
|  | @ -414,6 +417,10 @@ sub write_gcode { | |||
|      | ||||
|     # close our gcode file | ||||
|     close $fh; | ||||
|      | ||||
|     if ($tempfile) { | ||||
|         rename $tempfile, $file; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| # this method will return the supplied input file path after expanding its | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci