Redownloads a file even if it's been cached. Closes and unlinks the tempfile to help memory usage.
480578
def download!
      return download if file.nil?

      file.close
      file.unlink
      self.file = nil
      download
    end
1299750
def download(self, overwrite=True):
        
        if overwrite or not os.path.exists(self.file_path):
            _, f = tempfile.mkstemp()
            try:
                urlretrieve(self.DOWNLOAD_URL, f)
                extract_csv(f, self.file_path)
            finally:
                os.remove(f)
420026
def close(self):
        
        self.out_stream.close()
        # If we're asked to write in place, substitute the named
        # temporary file for the current file
        if self.in_place:
            shutil.move(self.temp_file.name, self.out)
761263
def download
      return io if io.is_a?(Tempfile)

      Tempfile.new(id, binmode: true).tap do |tempfile|
        IO.copy_stream(io, tempfile)
        tempfile.rewind
        tempfile.fsync
      end
    end
556385
def _cleanup_temporary_files(self):
        # type: (Downloader) -> None
        
        # iterate through dd map and cleanup files
        for key in self._dd_map:
            dd = self._dd_map[key]
            try:
                dd.cleanup_all_temporary_files()
            except Exception as e:
                logger.exception(e)
877401
private synchronized void refreshCachedData() throws IOException {
    IOUtils.closeStream(committedTxnId);
    
    File currentDir = journalStorage.getSingularStorageDir().getCurrentDir();
    this.lastPromisedEpoch = new PersistentLongFile(
        new File(currentDir, LAST_PROMISED_FILENAME), 0);
    this.lastWriterEpoch = new PersistentLongFile(
        new File(currentDir, LAST_WRITER_EPOCH), 0);
    this.committedTxnId = new BestEffortLongFile(
        new File(currentDir, COMMITTED_TXID_FILENAME),
        HdfsConstants.INVALID_TXID);
    metrics.lastWriterEpoch.set(lastWriterEpoch.get());
  }
1279913
def flush(self):
    """"""
    self.acquire()
    try:
      self.stream.flush()
    except (EnvironmentError, ValueError):
      # A ValueError is thrown if we try to flush a closed file.
      pass
    finally:
      self.release()
1116417
def clear_cache(m, files_processed):
    

    for what, reason, url, path in files_processed:
        cp = m.doc.downloader.cache_path(url)

        if m.cache.exists(cp):
            m.cache.remove(cp)
687162
def removeSingleCachedFile(self, fileStoreID):
        
        with self._CacheState.open(self) as cacheInfo:
            cachedFile = self.encodedFileID(fileStoreID)
            cachedFileStats = os.stat(cachedFile)
            # We know the file exists because this function was called in the if block.  So we
            # have to ensure nothing has changed since then.
            assert cachedFileStats.st_nlink <= self.nlinkThreshold, \
                   'Attempting to delete a global file that is in use by another job.'

            assert cachedFileStats.st_nlink >= self.nlinkThreshold, \
                   'A global file has too FEW links at deletion time. Our link threshold is incorrect!'
            # Remove the file size from the cached file size if the jobstore is not fileJobStore
            # and then delete the file
            os.remove(cachedFile)
            if self.nlinkThreshold != 2:
                cacheInfo.cached -= cachedFileStats.st_size
            if not cacheInfo.isBalanced():
                self.logToMaster('CACHE: The cache was not balanced on removing single file',
                                 logging.WARN)
            self.logToMaster('CACHE: Successfully removed file with ID \'%s\'.' % fileStoreID)
        return None
1232576
def destroy_temp(filename = nil)
      if filename.nil?
        @temp_files.each { |filename, file| file.unlink }
        @temp_files = {}
      else
        return if @temp_files[filename.to_sym].blank?
        @temp_files[filename.to_sym].unlink
        @temp_files.delete(filename.to_sym)
      end
    end
737108
public function close()
    {
        if($this->getType() == 'temp')
        {
            if(parent::close() == true)
            {
                //Only unlink temporary files
                if($this->getType() == 'temp') {
                    $this->unlink();
                }

                return true;
            }
        }

        if($this->getType() == 'memory') {
            return $this->flush();
        }

        return false;
    }
46492
def flush(self, file=str()):
        
        if file:
            Path(file).write_bytes(self._cache)
        else:
            self.path.write_bytes(self._cache)
1131178
def download(self, path, chunksize=None, chunk_callback=lambda _: False):
        
        chunksize = chunksize or self.chunksize
        bucket, obj = self._path_to_bucket_and_key(path)

        with tempfile.NamedTemporaryFile(delete=False) as fp:
            # We can't return the tempfile reference because of a bug in python: http://bugs.python.org/issue18879
            return_fp = _DeleteOnCloseFile(fp.name, 'r')

            # Special case empty files because chunk-based downloading doesn't work.
            result = self.client.objects().get(bucket=bucket, object=obj).execute()
            if int(result['size']) == 0:
                return return_fp

            request = self.client.objects().get_media(bucket=bucket, object=obj)
            downloader = http.MediaIoBaseDownload(fp, request, chunksize=chunksize)

            attempts = 0
            done = False
            while not done:
                error = None
                try:
                    _, done = downloader.next_chunk()
                    if chunk_callback(fp):
                        done = True
                except errors.HttpError as err:
                    error = err
                    if err.resp.status < 500:
                        raise
                    logger.warning('Error downloading file, retrying', exc_info=True)
                except RETRYABLE_ERRORS as err:
                    logger.warning('Error downloading file, retrying', exc_info=True)
                    error = err

                if error:
                    attempts += 1
                    if attempts >= NUM_RETRIES:
                        raise error
                else:
                    attempts = 0

        return return_fp
456314
def clear_file_cache(filename=None):
    """"""
    global file_cache, file2file_remap, file2file_remap_lines
    if filename is not None:
        if filename in file_cache:
            del file_cache[filename]
            pass
    else:
        file_cache = {}
        file2file_remap = {}
        file2file_remap_lines = {}
        pass
    return
277795
def close(self):
        '''
        

        '''

        if self.compressed_file is None:
            with self.path.open('rb+') as f:
                f.seek(0, 2)
                eof = f.tell()
                self._update_offset_value(f, self.gdr_head+36, 8, eof)
                if self.checksum:
                    f.write(self._md5_compute(f))
            return
# %%
        with self.path.open('rb+') as f:
            f.seek(0, 2)
            eof = f.tell()
            self._update_offset_value(f, self.gdr_head+36, 8, eof)

            with self.compressed_file.open('wb+') as g:
                g.write(bytearray.fromhex(CDF.V3magicNUMBER_1))
                g.write(bytearray.fromhex(CDF.V3magicNUMBER_2c))
                self._write_ccr(f, g, self.compression)

                if self.checksum:
                    g.seek(0, 2)
                    g.write(self._md5_compute(g))

        self.path.unlink()  # NOTE: for Windows this is necessary
        self.compressed_file.rename(self.path)
1067330
public void setPersistedFile(File file) throws FileNotFoundException
   {
      if (file instanceof SwapFile)
      {
         ((SwapFile)file).acquire(this);
      }

      this.file = file;

      // JCR-2326 Release the current ValueData from tempFile users before
      // setting its reference to null so it will be garbage collected.
      if (this.tempFile != null)
      {
         this.tempFile.release(this);
         this.tempFile = null;
      }

      this.stream = null;
   }
14631
def __uncache(self, file):
        

        if file in self.__files_cache:
            self.__files_cache.remove_content(file)