Create a temporary directory that is cleaned up on process exit.

  Arguments are as to tempfile.mkdtemp.

  :API: public
355003
def safe_mkdtemp(cleaner=_mkdtemp_atexit_cleaner, **kw):
  
  # Proper lock sanitation on fork [issue 6721] would be desirable here.
  with _MKDTEMP_LOCK:
    return register_rmtree(tempfile.mkdtemp(**kw), cleaner=cleaner)
732827
def _clear_temp_dir():
    
    tempdir = get_tempdir()
    for fname in os.listdir(tempdir):
        try:
            os.remove( os.path.join(tempdir, fname) )
        except Exception:
            pass
867237
def mkstemp(*args, **kwargs):
  
  fd, filename = tempfile.mkstemp(*args, **kwargs)
  os.close(fd)
  try:
    yield filename
  finally:
    os.remove(filename)
629126
def mkdtemp(hint=''):
    
    dirname = tempfile.mkdtemp(prefix='check-manifest-', suffix=hint)
    try:
        yield dirname
    finally:
        rmtree(dirname)
1025672
def _cleanup_temp_dir(self, base_dir):
        """"""
        if self._should_cleanup_temp_dir:
            logging.debug('Cleaning up temporary directory %s.', base_dir)
            if self._user is None:
                util.rmtree(base_dir, onerror=util.log_rmtree_error)
            else:
                rm = subprocess.Popen(self._build_cmdline(['rm', '-rf', '--', base_dir]),
                                      stderr=subprocess.PIPE)
                rm_output = rm.stderr.read().decode()
                rm.stderr.close()
                if rm.wait() != 0 or rm_output:
                    logging.warning("Failed to clean up temp directory %s: %s.",
                                    base_dir, rm_output)
        else:
            logging.info("Skipping cleanup of temporary directory %s.", base_dir)
688692
def tempfile(self):
        ""
        tf = tempfile.NamedTemporaryFile()
        tfn = tf.name
        tf.close()
        os.remove(tf.name)
        shutil.copy(self.fn, tfn)
        return tfn
1170439
def __mktmp(self):
        """"""
        try:
            if not os.path.isdir(self.location):
                os.makedirs(self.location)
        except Exception:
            log.debug(self.location, exc_info=1)
        return self
975313
def __clean_tmp(sfn):
    '''
    
    '''
    if sfn.startswith(os.path.join(tempfile.gettempdir(),
                                   salt.utils.files.TEMPFILE_PREFIX)):
        # Don't remove if it exists in file_roots (any saltenv)
        all_roots = itertools.chain.from_iterable(
                six.itervalues(__opts__['file_roots']))
        in_roots = any(sfn.startswith(root) for root in all_roots)
        # Only clean up files that exist
        if os.path.exists(sfn) and not in_roots:
            os.remove(sfn)
497256
def membuf_tempfile(memfile):
    """"""
    memfile.seek(0, 0)

    tmpfd, tmpname = mkstemp(suffix='.rar')
    tmpf = os.fdopen(tmpfd, "wb")

    try:
        while True:
            buf = memfile.read(BSIZE)
            if not buf:
                break
            tmpf.write(buf)
        tmpf.close()
    except:
        tmpf.close()
        os.unlink(tmpname)
        raise
    return tmpname
1104705
def _TempRootPath():
  """"""
  # `FLAGS.test_tmpdir` is defined only in test environment, so we can't expect
  # for it to be always defined.
  test_tmpdir = (
      compatibility.Environ("TEST_TMPDIR", default=None) or
      FLAGS.get_flag_value("test_tmpdir", default=None))

  if not os.path.exists(test_tmpdir):
    # TODO: We add a try-catch block to avoid rare race condition.
    # In Python 3 the exception being thrown is way more specific
    # (`FileExistsError`) but in Python 2 `OSError` is the best we can do. Once
    # support for Python 2 is dropped we can switch to catching that and remove
    # the conditional (EAFP).
    try:
      os.makedirs(test_tmpdir)
    except OSError as err:
      logging.error(err)

  # TODO(hanuszczak): Investigate whether this check still makes sense.
  if platform.system() == "Windows":
    return None

  return test_tmpdir
1175262
def _default_temporary_directory(self, prefix):
    """"""
    try:
      self.temporary_file = tempfile.NamedTemporaryFile(prefix=prefix)

    except OSError as err: # pragma: no cover
      logger.critical('Cannot create a system temporary directory: '+repr(err))
      raise securesystemslib.exceptions.Error(err)
1034456
def tmpdir(self):
        
        if self._tmpdir is None:
            self._tmpdir = mkdtemp(prefix="colin-", dir="/var/tmp")
        return self._tmpdir
1143350
def createHiddenFolder(self) -> 'File':
        

        if not self._autoDelete:
            raise Exception("Hidden folders can only be created within"
                            " an autoDelete directory")
        return tempfile.mkdtemp(dir=self._path, prefix=".")
303767
protected void deleteTempDirectory (final File tempDirectory)
  {
    try
    {
      FileUtils.deleteDirectory (tempDirectory);
    }
    catch (final IOException e)
    {
      getLog ().warn ("Failed to delete temporary directory: " + tempDirectory, e);
    }
  }
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;
    }
1237819
def _cleanup_tempdir(tempdir):
    """"""
    try:
        shutil.rmtree(tempdir)
    except OSError as err:
        if err.errno != errno.ENOENT:
            raise
1009101
public static File createTempDirectory(String prefix) {
	File temp = null;
	
	try {
	  temp = File.createTempFile(prefix != null ? prefix : "temp", Long.toString(System.nanoTime()));
	
	  if (!(temp.delete())) {
	    throw new IOException("Could not delete temp file: "
		  + temp.getAbsolutePath());
	  }
	
	  if (!(temp.mkdir())) {
	    throw new IOException("Could not create temp directory: "
	      + temp.getAbsolutePath());
	  }
	} catch (IOException e) {
	  throw new DukeException("Unable to create temporary directory with prefix " + prefix, e);
	}
	
	return temp;
  }