[Groonga-commit] groonga/gcs [master] Check existence of the source file before processing

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 9日 (木) 19:12:20 JST


SHIMODA Hiroshi	2012-08-09 19:12:20 +0900 (Thu, 09 Aug 2012)

  New Revision: 6a7a107b8de564bad8a1e6d6726ec2c84bd0128d
  https://github.com/groonga/gcs/commit/6a7a107b8de564bad8a1e6d6726ec2c84bd0128d

  Log:
    Check existence of the source file before processing

  Modified files:
    bin/gcs-post-sdf

  Modified: bin/gcs-post-sdf (+20 -14)
===================================================================
--- bin/gcs-post-sdf    2012-08-09 19:05:55 +0900 (cd0a40c)
+++ bin/gcs-post-sdf    2012-08-09 19:12:20 +0900 (c7e5c59)
@@ -27,6 +27,11 @@ if (!commandLine.options.source) {
 var sourceFile = CLI.resolve(commandLine.options.source);
 console.log('Processing: %s', sourceFile);
 
+if (!path.existsSync(sourceFile)) {
+  console.log('No such file');
+  return process.exit(1);
+}
+
 var format = sourceFile.match(/\.(xml|json)$/i);
 if (!format) {
   console.log('Unknown format');
@@ -41,26 +46,27 @@ if (format != 'json') {
   return process.exit(1);
 }
 
-var sourceText = fs.readFileSync(sourceFile, 'UTF-8');
-var batches = JSON.parse(sourceText);
-var processor = new BatchProcessor({
-      context: commandLine.context,
-      domain: commandLine.domain
-    });
-
 try {
-  processor.validate(batches);
-} catch (error) {
-  console.log('Validation failed.');
-  console.log(error.errors.join('\n'));
-  return process.exit(1);
-}
+  var batches = fs.readFileSync(sourceFile, 'UTF-8');
+  batches = JSON.parse(batches);
+  var processor = new BatchProcessor({
+        context: commandLine.context,
+        domain: commandLine.domain
+      });
+
+  try {
+    processor.validate(batches);
+  } catch (error) {
+    console.log('Validation failed.');
+    console.log(error.errors.join('\n'));
+    return process.exit(1);
+  }
 
-try {
   var result = processor.loadSync(batches);
   console.log('Status: %s', result.status);
   console.log('Added: %s', result.adds);
   console.log('Deleted: %s', result.deletes);
+
 } catch(error) {
   console.log('Fatal error!');
   console.log(error.message + '\n' + error.stack);
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index