~gero-bare/scratch/scratch-command-line-improvements

« back to all changes in this revision

Viewing changes to src/Scratch.vala

  • Committer: RabbitBot
  • Author(s): Geronimo Bareiro
  • Date: 2015-10-17 22:11:28 UTC
  • mfrom: (1574.1.4 scratch-text-editor)
  • Revision ID: rabbitbot-20151017221128-f0rbiemuc0f2h5ar
Add checks in ScratchApp to ensure files passed through cli are proper files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
                files.length = 0;
151
151
 
152
152
                foreach (string arg in args[1:unclaimed_args + 1]) {
153
 
                    files += File.new_for_commandline_arg (arg);
 
153
                    try {
 
154
                        var file = File.new_for_commandline_arg (arg);
 
155
 
 
156
                        if (!file.query_exists ())
 
157
                            continue;
 
158
 
 
159
                        var info = file.query_info ("standard::*", FileQueryInfoFlags.NONE, null);
 
160
                        if (info.get_file_type () == FileType.REGULAR)
 
161
                            files += file;
 
162
 
 
163
                    } catch (Error e) {
 
164
                        warning (e.message);
 
165
                    }
154
166
                }
155
167
 
156
 
                open (files, "");
 
168
                if (files.length > 0)
 
169
                    open (files, "");
157
170
            }
158
171
 
159
172
            return Posix.EXIT_SUCCESS;
214
227
            else
215
228
                view = window.get_current_view ();
216
229
 
217
 
            for (int i = 0; i < files.length; i++) {
218
 
                // Check if the given path is a directory
219
 
                try {
220
 
                    var info = files[i].query_info ("standard::*", FileQueryInfoFlags.NONE, null);
221
 
                    if (info.get_file_type () != FileType.DIRECTORY) {
222
 
                        var doc = new Scratch.Services.Document (window.main_actions, files[i]);
223
 
                        view.open_document (doc);
224
 
                    }
225
 
                    else
226
 
                        warning ("\"%s\" is a directory, not opening it", files[i].get_basename ());
227
 
                } catch (Error e) {
228
 
                    warning (e.message);
229
 
                }
 
230
            foreach (var file in files) {
 
231
                var doc = new Scratch.Services.Document (window.main_actions, file);
 
232
                view.open_document (doc);
230
233
            }
231
234
        }
232
235