Requires that the file referred to by `backup_file` exists in the file
    system before running the decorated function.
484324
def require_backup_exists(func):
    
    def new_func(*args, **kwargs):
        backup_file = kwargs['backup_file']
        if not os.path.exists(backup_file):
            raise RestoreError("Could not find file '{0}'".format(backup_file))
        return func(*args, **kwargs)
    return new_func
790974
function fileExists(file) {
    try {
        var targetStat = fs.statSync(file);
        if (targetStat.isDirectory() ) {
            throw new Error("File exists but it's a driectory: " + file);
        }
    }
    catch(err) {
        if (err.code == 'ENOENT') {         // No such file or directory
            return false;
        }
        else {
            throw err;
        }
    }
    return true;
}
393077
function exists(file) {
  try {
    fs.lstatSync(file);
    return true;
  } catch (e) {
    if (e.code === 'ENOENT' || e.code === 'ENOTDIR') {
      return false;
    } else {
      throw e;
    }
  }
}
35831
def rm_file_if_exists(path, filename):
    
    _full_path = os.path.join(path, filename)
    if os.path.exists(_full_path):
        os.remove(_full_path)
    return
412626
def backup_file(filename):
    
    if not os.path.exists(filename):
        return

    BACKUP_SUFFIX = ".sprinter.bak"

    backup_filename = filename + BACKUP_SUFFIX
    shutil.copyfile(filename, backup_filename)
598011
def should_skip_file(name):
    
    if name.endswith(('~', '.bak')):
        return 'Skipping backup file %(filename)s'
    if name.endswith(('.pyc', '.pyo')):
        return 'Skipping %s file ' % os.path.splitext(name)[1] + '%(filename)s'
    if name.endswith('$py.class'):
        return 'Skipping $py.class file %(filename)s'
    return None
304815
def depends(func):
    
    from jcvi.apps.base import need_update, listify

    infile = "infile"
    outfile = "outfile"

    def wrapper(*args, **kwargs):
        assert outfile in kwargs, \
            "You need to specify `outfile=` on function call"
        if infile in kwargs:
            infilename = listify(kwargs[infile])
            for x in infilename:
                assert op.exists(x), \
                    "The specified infile `{0}` does not exist".format(x)

        outfilename = kwargs[outfile]
        if need_update(infilename, outfilename):
            return func(*args, **kwargs)
        else:
            msg = "File `{0}` exists. Computation skipped." \
                .format(outfilename)
            logging.debug(msg)

        outfilename = listify(outfilename)

        for x in outfilename:
            assert op.exists(x), \
                "Something went wrong, `{0}` not found".format(x)

        return outfilename

    return wrapper
1127231
def _options_file_exists(name):
    '''
    
    '''
    return os.path.isfile(os.path.join(_options_dir(name), 'options'))
522197
function _shouldKeepExisting(file, text)
{
return Promise.coroutine(function *() {
	if (!(yield fs.fileExists(file)))
		return false;

//	var st = yield fs.stat(file);
//	if (st > _ThisBuild)
//		l.logw("File is used multiple times: '" + file)+"'");

	// read the existing file and compare with new contents. ignore if nothing changed
	try
	{
		var existingText = yield fs.readFile(file, "utf8");
		if (existingText == text)
		{
			//l.vlog("Skipping (unchanged): '" + file + "'");
			return true;
		}
	}
	catch (e)
	{
		l.logw("Failed to compare existing file " + path.basename(file) + " (will try and overwrite): " + _.niceStackTrace(e));
		// and continue below...
	}
	return false;
})();
}
858070
def before_save(file_or_dir):
    
    dir_name = os.path.dirname(os.path.abspath(file_or_dir))
    if not os.path.exists(dir_name):
        os.makedirs(dir_name)
714189
def _check_file_existence(self, files):
        ''''''
        for f in files:
            if not os.path.isfile(f):
                logging.error("The file '%s' does not appear to exist, stopping" % f)
                exit(1)
202769
async function fileExists(f) {
  debug(`fileExists called with: ${JSON.stringify(arguments)}`);
  try {
    await fs.statAsync(f);
    return f;
  } catch (e) {
    throw e;
  }
}
514229
def exists_locally(cls, path):
    """"""
    # If INFO file doesn't exist, consider resource does NOT exist, as it would
    # prevent guessing the `extract_method`.
    return (tf.io.gfile.exists(path) and
            tf.io.gfile.exists(_get_info_path(path)))
315679
def remote_file_exists(self, url):
        
        status = requests.head(url).status_code

        if status != 200:
            raise RemoteFileDoesntExist
1042686
def _CheckStorageFile(self, storage_file_path):  # pylint: disable=arguments-differ
    
    if os.path.exists(storage_file_path):
      if not os.path.isfile(storage_file_path):
        raise errors.BadConfigOption(
            'Storage file: {0:s} already exists and is not a file.'.format(
                storage_file_path))
      logger.warning('Appending to an already existing storage file.')

    dirname = os.path.dirname(storage_file_path)
    if not dirname:
      dirname = '.'

    # TODO: add a more thorough check to see if the storage file really is
    # a plaso storage file.

    if not os.access(dirname, os.W_OK):
      raise errors.BadConfigOption(
          'Unable to write to storage file: {0:s}'.format(storage_file_path))
212129
private void restoreBackupIncremental() {

        try {
            if (fa.isStreamElement(fileName + ".backup")) {
                RAShadowFile.restoreFile(fileName + ".backup",
                                         fileName + ".data");
            } else {
/*
                // this is to ensure file has been written fully but it is not necessary
                // as semantics dictate that if a backup does not exist, the file
                // was never changed or was fully written to
                if (FileUtil.exists(cacheFileName)) {
                    int flags = DataFileCache.getFlags(cacheFileName);

                    if (!BitMap.isSet(flags, DataFileCache.FLAG_ISSAVED)) {
                        FileUtil.delete(cacheFileName);
                    }
                }
*/
            }

            deleteBackup();
        } catch (IOException e) {
            throw Error.error(ErrorCode.FILE_IO_ERROR, fileName + ".backup");
        }
    }
243446
function doesFileExist(filePath) {
    if (!fileExistsCache.hasOwnProperty(filePath)) {
        fileExistsCache[filePath] = fs.existsSync(filePath);
    }

    return fileExistsCache[filePath];
}