All files / src/lib/helpers getTmp.ts

64.71% Statements 11/17
50% Branches 6/12
100% Functions 1/1
64.71% Lines 11/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 312x 2x 2x   2x 1x 1x               1x                 1x 1x   1x     2x  
import fs from "fs-extra";
import os from "os";
import isElectron from "./isElectron";
 
const getTmp = (create = true) => {
  let tmpPath = os.tmpdir();
  Iif (isElectron()) {
    // eslint-disable-next-line global-require
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    const settings = require("electron-settings");
    Iif (settings.get("tmpDir")) {
      tmpPath = settings.get("tmpDir");
    }
  }
  if (
    tmpPath.indexOf(" ") === -1 &&
    tmpPath.indexOf(".itch") === -1 &&
    (process.platform !== "win32" || tmpPath.length < 35)
  ) {
    // Ok
  } else Eif (process.platform === "win32") {
    tmpPath = "C:\\tmp";
  } else tmpPath = "/tmp";
  if (create) {
    fs.ensureDirSync(tmpPath);
  }
  return tmpPath;
};
 
export default getTmp;