Skip to content

Commit 579c630

Browse files
committed
Allow single path when optimizing. Preserve file permissions.
1 parent 8e9b861 commit 579c630

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Console/fileconverter.drush.inc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,18 @@ function fileconverter_drush_init() {
119119
function drush_fileconverter_convert($source = NULL, $destination = NULL) {
120120
// Require the arguments.
121121
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+
}
124129
}
125130

131+
// Remember the file stats of the source file.
132+
$file_stat = NULL;
133+
126134
// Normalize the file paths.
127135
$fc = FileConverter\FileConverter::factory();
128136
$stdin = $stdout = FALSE;
@@ -169,6 +177,9 @@ function drush_fileconverter_convert($source = NULL, $destination = NULL) {
169177
return;
170178
}
171179
}
180+
else {
181+
$file_stat = stat($source);
182+
}
172183
}
173184
if ($destination{0} !== '/') {
174185
if ($destination === '-') {
@@ -224,6 +235,12 @@ function drush_fileconverter_convert($source = NULL, $destination = NULL) {
224235
readfile($destination);
225236
unlink($destination);
226237
}
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+
}
227244
}
228245

229246
function drush_fileconverter_list($list_name = NULL) {

0 commit comments

Comments
 (0)