All files / src/lib/helpers getTmp.ts

61.11% Statements 11/18
46.66% Branches 7/15
100% Functions 1/1
61.11% Lines 11/18

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 = async (create = true) => {
  let tmpPath = os.tmpdir();
  Iif (isElectron()) {
    // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
    const { settingsGet } = require("lib/helpers/appSettings");
    const electronSettingsTmp = await settingsGet("tmpDir");
    if (electronSettingsTmp) {
      tmpPath = electronSettingsTmp;
    }
  }
  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";
  Eif (create) {
    fs.ensureDirSync(tmpPath);
  }
  return tmpPath;
};
 
export default getTmp;