@@ -110,19 +110,12 @@ impl Drop for SuppressGDALErrorLog {
110
110
/// Copies the given file to a temporary file and opens it for writing. When the returned
111
111
/// `TempPath` is dropped, the file is deleted.
112
112
pub 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 ( )
118
114
. suffix ( ".gpkg" )
119
115
. tempfile ( )
120
116
. 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 ( ) ;
126
119
127
120
let ds = Dataset :: open_ex (
128
121
& temp_path,
@@ -139,11 +132,7 @@ pub fn open_gpkg_for_update(path: &Path) -> (TempPath, Dataset) {
139
132
/// Copies the given file to a temporary file and opens it for writing. When the returned
140
133
/// `TempPath` is dropped, the file is deleted.
141
134
pub 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 ( )
147
136
// using the whole filename as suffix should be fine (can't
148
137
// use .extension() for .shp.zip and such)
149
138
. suffix (
@@ -153,12 +142,8 @@ pub fn open_dataset_for_update(path: &Path) -> (TempPath, Dataset) {
153
142
. as_ref ( ) ,
154
143
)
155
144
. tempfile ( )
156
- . 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) ;
145
+ . unwrap ( ) . into_temp_path ( ) ;
146
+ std:: fs:: copy ( path, & temp_path) . unwrap ( ) ;
162
147
163
148
let ds = Dataset :: open_ex (
164
149
& temp_path,
0 commit comments