@@ -119,10 +119,18 @@ function fileconverter_drush_init() {
119
119
function drush_fileconverter_convert ($ source = NULL , $ destination = NULL ) {
120
120
// Require the arguments.
121
121
if (!isset ($ source ) || !isset ($ destination ) || $ destination === '' ) {
122
- drush_print ("USAGE: fileconverter 'source.ext1' 'destination.ext2' " );
123
- return ;
122
+ if (drush_get_option ('optimize ' ) === TRUE && isset ($ source )) {
123
+ $ destination = $ source ;
124
+ }
125
+ else {
126
+ drush_print ("USAGE: fileconverter 'source.ext1' 'destination.ext2' " );
127
+ return ;
128
+ }
124
129
}
125
130
131
+ // Remember the file stats of the source file.
132
+ $ file_stat = NULL ;
133
+
126
134
// Normalize the file paths.
127
135
$ fc = FileConverter \FileConverter::factory ();
128
136
$ stdin = $ stdout = FALSE ;
@@ -169,6 +177,9 @@ function drush_fileconverter_convert($source = NULL, $destination = NULL) {
169
177
return ;
170
178
}
171
179
}
180
+ else {
181
+ $ file_stat = stat ($ source );
182
+ }
172
183
}
173
184
if ($ destination {0 } !== '/ ' ) {
174
185
if ($ destination === '- ' ) {
@@ -224,6 +235,12 @@ function drush_fileconverter_convert($source = NULL, $destination = NULL) {
224
235
readfile ($ destination );
225
236
unlink ($ destination );
226
237
}
238
+ elseif (isset ($ file_stat )) {
239
+ // Preserve the same owner/mode as the source.
240
+ chown ($ destination , $ file_stat ['uid ' ]);
241
+ chgrp ($ destination , $ file_stat ['gid ' ]);
242
+ chmod ($ destination , $ file_stat ['mode ' ]);
243
+ }
227
244
}
228
245
229
246
function drush_fileconverter_list ($ list_name = NULL ) {
0 commit comments