How to use the mz/fs.rename function in mz

To help you get started, we’ve selected a few mz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jakoblo / ufo / src / js / filesystem / write / child-worker / fs-write-worker.js View on Github external
function tryRename() {
    console.log('FS try rename')
    if (options.clobber) {
      console.log('FS rename')
      fs.rename(source, dest, function(err) {
        if (!err) return sendDone();
        if (err.code !== c.ERROR_RENAME_CROSS_DEVICE) return sendError(err);
        copy(source, dest);
      });
    } else {
      console.log('FS link')
      fs.link(source, dest, function(err) {
        if (err) {
          console.log(err)
          if (err.code === c.ERROR_RENAME_CROSS_DEVICE) { // cross-device link not permitted -> do a real copy
            copy(source, dest); 
            return;
          }
          if (err.code === c.ERROR_IS_DIR || err.code === c.ERROR_OPERATION_NOT_PERMITTED) {
            copy(source, dest);
            return;
github evaera / RoVer / src / DiscordServer.js View on Github external
}
    this.ongoingSettingsUpdate = true

    this.settings[key] = value

    const tmpSettingsPath = this.settingsPath + '.tmp'
    await fs.writeFile(tmpSettingsPath, JSON.stringify(this.settings))

    try {
      JSON.parse(await fs.readFile(tmpSettingsPath, 'utf8')) // Throws if file got corrupted
    } catch (e) {
      this.ongoingSettingsUpdate = false
      throw new Error('Atomic save failed: file corrupted. Try again.')
    }

    await fs.rename(tmpSettingsPath, this.settingsPath)
    this.ongoingSettingsUpdate = false
  }
github sourcegraph / sourcegraph / lsif / src / worker / conversion / conversion.ts View on Github external
const dumpRecord = await logAndTraceCall({ logger, span }, 'Inserting dump', () =>
                dumpManager.insertDump(repository, commit, root, uploadedAt, entityManager)
            )

            await dependencyManager.addPackagesAndReferences(
                dumpRecord.id,
                packages,
                references,
                { logger, span },
                entityManager
            )
            return dumpRecord
        })

        // Move the temp file where it can be found by the server
        await fs.rename(tempFile, dbFilename(settings.STORAGE_ROOT, dump.id, repository, commit))

        logger.info('Created dump', {
            repository: dump.repository,
            commit: dump.commit,
            root: dump.root,
        })
    } catch (error) {
        // Don't leave busted artifacts
        await fs.unlink(tempFile)
        throw error
    }

    await fs.unlink(filename)
}
github sourcegraph / sourcegraph / lsif / src / server.ts View on Github external
async function ensureFilenamesAreIDs(db: Connection): Promise {
    const doneFile = path.join(STORAGE_ROOT, 'id-based-filenames')
    if (await fs.exists(doneFile)) {
        // Already migrated.
        return
    }

    for (const dump of await db.getRepository(LsifDump).find()) {
        const oldFile = dbFilenameOld(STORAGE_ROOT, dump.repository, dump.commit)
        const newFile = dbFilename(STORAGE_ROOT, dump.id, dump.repository, dump.commit)
        if (!(await fs.exists(oldFile))) {
            continue
        }
        await fs.rename(oldFile, newFile)
    }

    // Create an empty done file to record that all files have been renamed.
    await fs.close(await fs.open(doneFile, 'w'))
}
github jakoblo / ufo / src / js / filesystem / write / child-worker / fs-write-worker-move.js View on Github external
return new Promise(function(resolve, reject) {
    // Start with the easiest and fastest ways for move files/folders
    // and work up to more expensive ways

    if (subTask.clobber) {
      fs.rename(subTask.source, subTask.destination, function(err) {
        if (err) {
          switch (err.code) {
            case c.ERROR_RENAME_CROSS_DEVICE:
              moveWithCopy(subTask);
              return;
            default:
              reject(err);
              return;
          }
        }
        resolve();
      });
    } else {
      fs.link(subTask.source, subTask.destination, function(err) {
        if (err) {
          switch (err.code) {
github sourcegraph / sourcegraph / lsif / src / server / server.ts View on Github external
async function ensureFilenamesAreIDs(db: Connection): Promise {
    const doneFile = path.join(settings.STORAGE_ROOT, 'id-based-filenames')
    if (await fs.exists(doneFile)) {
        // Already migrated.
        return
    }

    for (const dump of await db.getRepository(pgModels.LsifDump).find()) {
        const oldFile = dbFilenameOld(settings.STORAGE_ROOT, dump.repository, dump.commit)
        const newFile = dbFilename(settings.STORAGE_ROOT, dump.id, dump.repository, dump.commit)
        if (!(await fs.exists(oldFile))) {
            continue
        }
        await fs.rename(oldFile, newFile)
    }

    // Create an empty done file to record that all files have been renamed.
    await fs.close(await fs.open(doneFile, 'w'))
}
github flying-sheep / rollup-plugin-postcss-modules / test / fixtures.js View on Github external
input: `${casePath}/in.css`,
		output: { file: `${resultPath}/out.js` },
		plugins: [
			await postcss(options),
			externalGlobals({ [styleInjectPath]: 'styleInject' }),
		],
	})
	
	await bundle.write({
		file: `${resultPath}/out.js`,
		format: 'es',
	})
	
	const dPath = `${casePath}/in.css.d.ts`
	if (await fs.exists(dPath)) {
		fs.rename(dPath, `${resultPath}/in.css.d.ts`)
	}
	
	return match()
} catch (e) {
	console.error(e.stack)
	throw e
}})
github sourcegraph / sourcegraph / lsif / src / server.ts View on Github external
async function moveDatabaseFilesToSubdir(): Promise {
    for (const filename of await fs.readdir(STORAGE_ROOT)) {
        if (filename.endsWith('.db')) {
            await fs.rename(path.join(STORAGE_ROOT, filename), path.join(STORAGE_ROOT, constants.DBS_DIR, filename))
        }
    }
}
github sourcegraph / sourcegraph / lsif / src / server / server.ts View on Github external
async function moveDatabaseFilesToSubdir(): Promise {
    for (const filename of await fs.readdir(settings.STORAGE_ROOT)) {
        if (filename.endsWith('.db')) {
            await fs.rename(
                path.join(settings.STORAGE_ROOT, filename),
                path.join(settings.STORAGE_ROOT, constants.DBS_DIR, filename)
            )
        }
    }
}