Prepare a temporary filesystem for writing to read_path

    The file will be moved to write_path on close if modified.
329324
def _prepare_write_fs(read_fs, cache, read_path, readwrite_mode=True):
    '''
    
    '''

    with _get_write_fs() as write_fs:

        # If opening in read/write or append mode, make sure file data is
        # accessible
        if readwrite_mode:

            if not write_fs.isfile(read_path):
                _touch(write_fs, read_path)

                if read_fs.isfile(read_path):
                    fs.utils.copyfile(
                        read_fs, read_path, write_fs, read_path)

        else:
            _touch(write_fs, read_path)

        yield write_fs
865764
def make_temp_path(path, new_ext=None):
    
    root, ext = os.path.splitext(path)
    if new_ext is None:
        new_ext = ext
    temp_path = root + TEMP_EXTENSION + new_ext
    return temp_path
930428
def tmp_file(*args, **kwargs):
    
    fileno, path = tempfile.mkstemp(*args, **kwargs)

    # create the file
    with open(path, "w") as f:
        f.write("")

    # yield it
    try:
        yield fileno, path
    finally:
        if os.path.exists(path):
            os.remove(path)
1231456
private function prepareTmpDir()
    {
        $tempDir = $this->file->get(self::SETTING_DESTINATION_DIR) . DIRECTORY_SEPARATOR . uniqid('install-');

        // If the temporary folder could not be created, error out.
        // @codingStandardsIgnoreStart - we silence on purpose here as we create an exception on error.
        if (!@mkdir($tempDir, 0700)) {
        // @codingStandardsIgnoreEnd
            throw new \RuntimeException('Could not create the temporary directory');
        }

        $this->tempDir = $tempDir;
    }
103550
def temporary_file(mode):
    
    tempdir = tempfile.gettempdir()
    basename = 'tmpfile-%s' % (uuid.uuid4())
    full_filename = os.path.join(tempdir, basename)
    if 'w' not in mode:
        # We need to create the file before we can open
        # it in 'r' mode.
        open(full_filename, 'w').close()
    try:
        with open(full_filename, mode) as f:
            yield f
    finally:
        os.remove(f.name)
723836
def prepend(line, path):
    
    if isinstance(line, str):
        line = line.encode('utf-8')
    if not line.endswith(b'\n'):
        line += b'\n'
    temp = tempfile.NamedTemporaryFile('wb')
    temp_name = temp.name # We really only need a random path-safe name
    temp.close()
    with open(temp_name, 'wb') as temp:
        temp.write(line)
        with open(path, 'rb') as r:
            temp.write(r.read())
    # Now replace the original with the modified version
    shutil.move(temp_name, path)
138678
protected function prepareTempFolder()
    {
        $this->tmpFolder = sys_get_temp_dir() . '/PrestaSitemaps-' . uniqid();
        $this->filesystem->mkdir($this->tmpFolder);
    }
69126
def write_file(path)
      exec "mkdir -p #{File.dirname(path).gsub(/ /, "\\ ")}"
      Tempfile.open(File.basename(path)) do |f|
        yield f
        f.flush
        remote_path = %Q{"#{@user}@#{host}:#{path.gsub(/ /, "\\ ")}"}
        puts "Writing to #{remote_path}"
        `scp '#{f.path}' #{remote_path}`
      end
    end
749430
def save_file(path, text):
    
    dir = os.path.dirname(path)
    if not os.path.exists(dir):
        os.makedirs(dir)

    fd = open(path, 'w')
    try:
        fd.write(text)
    finally:
        fd.close()
355811
def atomic_write(file_name)
      temp_dir = File.join(Geminabox.data, "_temp")
      FileUtils.mkdir_p(temp_dir)
      temp_file = Tempfile.new("." + File.basename(file_name), temp_dir)
      temp_file.binmode
      yield temp_file
      temp_file.close
      File.rename(temp_file.path, file_name)
      File.chmod(Geminabox.gem_permissions, file_name)
    end
562887
def write_path(path, s, owner=None, group=None, mode=None,
               utimes=None, sync=False):
    
    path = os.path.abspath(path)
    fd, tmp_path = tempfile.mkstemp(suffix='.tmp',
                                    prefix='.ansible_mitogen_transfer-',
                                    dir=os.path.dirname(path))
    fp = os.fdopen(fd, 'wb', mitogen.core.CHUNK_SIZE)
    LOG.debug('write_path(path=%r) temporary file: %s', path, tmp_path)

    try:
        try:
            if mode:
                set_file_mode(tmp_path, mode, fd=fp.fileno())
            if owner or group:
                set_file_owner(tmp_path, owner, group, fd=fp.fileno())
            fp.write(s)
        finally:
            fp.close()

        if sync:
            os.fsync(fp.fileno())
        os.rename(tmp_path, path)
    except BaseException:
        os.unlink(tmp_path)
        raise

    if utimes:
        os.utime(path, utimes)
947005
def make_file(path, contents='', overwrite=False):
    
    if overwrite or not os.path.exists(path):
        with open(path, 'w') as fh:
            fh.write(contents)
        return True

    return False
1371998
def save(self):
        # type: () -> None
        
        self._ensure_have_load_only()

        for fname, parser in self._modified_parsers:
            logger.info("Writing to %s", fname)

            # Ensure directory exists.
            ensure_dir(os.path.dirname(fname))

            with open(fname, "w") as f:
                parser.write(f)
378649
def save(self, path):
        
        # remember and restore file position
        pos = self.tell()
        self.seek(0)

        with fopen(path, 'wb') as output:
            output.truncate(self.length)
            for chunk in iter(lambda: self.read(1024), b''):
                output.write(chunk)

        self.seek(pos)
23018
def make_temp(suffix="", prefix="tmp", dir=None):
    
    temporary = tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir)
    os.close(temporary[0])
    try:
        yield temporary[1]
    finally:
        os.remove(temporary[1])
1071732
public function prepareForRestart() {
		parent::prepareForRestart();
		// if the file we've been building is missing, lets fix it up
		if (!$this->tempFile || !file_exists($this->tempFile)) {
			$tmpfile = tempnam(getTempFolder(), 'postsitemap');
			if (file_exists($tmpfile)) {
				$this->tempFile = $tmpfile;
			}
			$this->currentStep = 0;
			$this->toProcess = $this->getProcessIds();
		}
	}
840885
def MakeDir(self, path="temp"):
        
        full_path = _os.path.join(self.path_home, path)

        # only make it if it doesn't exist!
        if not _os.path.exists(full_path): _os.makedirs(full_path)