@@ -110,19 +110,12 @@ impl Drop for SuppressGDALErrorLog {
110110/// Copies the given file to a temporary file and opens it for writing. When the returned
111111/// `TempPath` is dropped, the file is deleted.
112112pub fn open_gpkg_for_update ( path : & Path ) -> ( TempPath , Dataset ) {
113- use std:: fs;
114- use std:: io:: Write ;
115-
116- let input_data = fs:: read ( path) . unwrap ( ) ;
117- let ( mut file, temp_path) = tempfile:: Builder :: new ( )
113+ let temp_path = tempfile:: Builder :: new ( )
118114 . suffix ( ".gpkg" )
119115 . tempfile ( )
120116 . unwrap ( )
121- . into_parts ( ) ;
122- file. write_all ( & input_data) . unwrap ( ) ;
123- // Close the temporary file so that Dataset can open it safely even if the filesystem uses
124- // exclusive locking (Windows?).
125- drop ( file) ;
117+ . into_temp_path ( ) ;
118+ std:: fs:: copy ( path, & temp_path) . unwrap ( ) ;
126119
127120 let ds = Dataset :: open_ex (
128121 & temp_path,
@@ -139,11 +132,7 @@ pub fn open_gpkg_for_update(path: &Path) -> (TempPath, Dataset) {
139132/// Copies the given file to a temporary file and opens it for writing. When the returned
140133/// `TempPath` is dropped, the file is deleted.
141134pub fn open_dataset_for_update ( path : & Path ) -> ( TempPath , Dataset ) {
142- use std:: fs;
143- use std:: io:: Write ;
144-
145- let input_data = fs:: read ( path) . unwrap ( ) ;
146- let ( mut file, temp_path) = tempfile:: Builder :: new ( )
135+ let temp_path = tempfile:: Builder :: new ( )
147136 // using the whole filename as suffix should be fine (can't
148137 // use .extension() for .shp.zip and such)
149138 . suffix (
@@ -154,11 +143,8 @@ pub fn open_dataset_for_update(path: &Path) -> (TempPath, Dataset) {
154143 )
155144 . tempfile ( )
156145 . unwrap ( )
157- . into_parts ( ) ;
158- file. write_all ( & input_data) . unwrap ( ) ;
159- // Close the temporary file so that Dataset can open it safely even if the filesystem uses
160- // exclusive locking (Windows?).
161- drop ( file) ;
146+ . into_temp_path ( ) ;
147+ std:: fs:: copy ( path, & temp_path) . unwrap ( ) ;
162148
163149 let ds = Dataset :: open_ex (
164150 & temp_path,
0 commit comments