瀏覽代碼

Fix #19, better to check if a file exist before trying to copy it 😂

Godzil 7 年之前
父節點
當前提交
ed4f398062
共有 1 個文件被更改,包括 19 次插入1 次删除
  1. 19 1
      src/series.ts

+ 19 - 1
src/series.ts

@@ -9,6 +9,21 @@ import url = require('url');
 import log  = require('./log');
 const persistent = '.crpersistent';
 
+/**
+ * Check if a file exist..
+ */
+function fileExist(path: string)
+{
+  try
+  {
+    fs.statSync(path);
+    return true;
+  } catch (e)
+  {
+    return false;
+  }
+}
+
 /**
  * Streams the series to disk.
  */
@@ -17,7 +32,10 @@ export default function(config: IConfig, address: string, done: (err: Error) =>
   const persistentPath = path.join(config.output || process.cwd(), persistent);
 
   /* Make a backup of the persistent file in case of */
-  fse.copySync(persistentPath, persistentPath + '.backup');
+  if (fileExist(persistentPath))
+  {
+    fse.copySync(persistentPath, persistentPath + '.backup');
+  }
 
   fs.readFile(persistentPath, 'utf8', (err: Error, contents: string) =>
   {