Delete files older then a certain age (gc_lifetime)
192958
protected function garbageCollect()
    {
        foreach (Finder::create()->files()->name('*.json')->date('< ' . $this->gc_lifetime . ' hour ago')->in(
            $this->dirname
        ) as $file) {
            $this->files->delete($file->getRealPath());
        }
    }
435800
public function cleanUpGarbage()
    {
        $cacheFilesExpire = time() - $this->getCacheLifetime() * 3600 * 24;

        // relies on templates sorting order being related to their modification dates
        $upperLimit = $this->getPhpCodeDestination() . $this->getFunctionNamePrefix($cacheFilesExpire) . '_';
        $lowerLimit = $this->getPhpCodeDestination() . $this->getFunctionNamePrefix(0);

        // second * gets phptal:cache
        $cacheFiles = glob($this->getPhpCodeDestination() . 'tpl_????????_*.' . $this->getPhpCodeExtension() . '*');

        if ($cacheFiles) {
            foreach ($cacheFiles as $index => $file) {

                // comparison here skips filenames that are certainly too new
                if (strcmp($file, $upperLimit) <= 0 || substr($file, 0, strlen($lowerLimit)) === $lowerLimit) {
                    $time = filemtime($file);
                    if ($time && $time < $cacheFilesExpire) {
                        @unlink($file);
                    }
                }
            }
        }
    }
1018927
def prune_old(self):
        
        path = self.pubdir
        dirmask = self.dirmask
        expire = self.expire
        expire_limit = int(time.time()) - (86400 * expire)

        logger.info('Pruning directories older than %d days', expire)

        if not os.path.isdir(path):
            logger.warning('Dir %r not found -- skipping pruning', path)
            return

        for entry in os.listdir(path):
            logger.debug('Found: %r', entry)
            if os.path.isdir(os.path.join(path, entry)):
                try: 
                    stamp = time.mktime(time.strptime(entry, dirmask))
                except ValueError as e:
                    logger.info('Dir %r did not match dirmask %r: %r', entry, dirmask, e)
                    logger.info('Skipping %r', entry)
                    continue

                if stamp < expire_limit:
                    shutil.rmtree(os.path.join(path, entry))
                    logger.info('File Publisher: Pruned old dir: %r', entry)
                else:
                    logger.info('%r is still active', entry)
            else:
                logger.info('%r is not a directory. Skipping.', entry)

        logger.info('Finished with pruning')
276937
def maybe_clean(self):
        """"""

        now = time.time()
        if self.next_cleaning <= now:
            keys_to_delete = []
            for (k, v) in self.data.iteritems():
                if v.expiration <= now:
                    keys_to_delete.append(k)
            for k in keys_to_delete:
                del self.data[k]
            now = time.time()
            self.next_cleaning = now + self.cleaning_interval
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)
147124
def delete(filething):
    

    t = OggTheora(filething)
    filething.fileobj.seek(0)
    t.delete(filething)
1236743
def _cleanup(self):
        """"""
        for filename in os.listdir(self._storage_dir):
            file_path = path.join(self._storage_dir, filename)
            file_stat = os.stat(file_path)
            evaluate = max(file_stat.st_ctime, file_stat.st_mtime)
            if evaluate + self._duration < time.time():
                LOGGER.debug('Removing stale file: %s', file_path)
                os.unlink(file_path)
351143
static function gc()
    {
        $rcube = rcube::get_instance();
        $db    = $rcube->get_dbh();
        $now   = $db->now();

        $db->query("DELETE FROM " . $db->table_name('cache_messages', true)
              ." WHERE `expires` < $now");

        $db->query("DELETE FROM " . $db->table_name('cache_index', true)
              ." WHERE `expires` < $now");

        $db->query("DELETE FROM ".$db->table_name('cache_thread', true)
              ." WHERE `expires` < $now");
    }
563367
public function gc($lifetime)
    {
        $sql    = 'DELETE from tbl_sessions where LAST_ACCESSED < DATE_SUB(NOW(), INTERVAL :LIFETIME SECOND)';
        $delete = $this->_db->prepare($sql);
        $count  = $delete->execute(array(':LIFETIME' => $lifetime));

        return true;

    }
725022
def remove_old(self, max_log_time):
        """"""
        files = glob.glob('{}/queue-*'.format(self.log_dir))
        files = list(map(lambda x: os.path.basename(x), files))

        for log_file in files:
            # Get time stamp from filename
            name = os.path.splitext(log_file)[0]
            timestamp = name.split('-', maxsplit=1)[1]

            # Get datetime from time stamp
            time = datetime.strptime(timestamp, '%Y%m%d-%H%M')
            now = datetime.now()

            # Get total delta in seconds
            delta = now - time
            seconds = delta.total_seconds()

            # Delete log file, if the delta is bigger than the specified log time
            if seconds > int(max_log_time):
                log_filePath = os.path.join(self.log_dir, log_file)
                os.remove(log_filePath)
174523
static function gc()
    {
        $rcube = rcube::get_instance();
        $db    = $rcube->get_dbh();

        $db->query("DELETE FROM " . $db->table_name('cache', true) . " WHERE `expires` < " . $db->now());
    }
574332
public void sweepFile(long now, Path p) throws Exception {
        if (p == null) {
            return;
        }
        long expiry = getExpiryFromFilename(p.getFileName().toString());
        // files with 0 expiry never expire
        if (expiry > 0 && ((now - expiry) >= (5 * TimeUnit.SECONDS.toMillis(gracePeriodSec)))) {
            Files.deleteIfExists(p);
            if (log.isDebugEnabled()) {
                log.debug("Sweep deleted " + p.getFileName());
            }
        }
    }
169642
def cleanup(bucket, prefix, versions)
      objects = @con.get_bucket(bucket, :prefix => prefix).body['Contents']

      return if objects.size <= versions

      objects[0...(objects.size - versions)].each do |o|
       Mongolicious.logger.info("Removing outdated version #{o['Key']}")
       @con.delete_object(bucket, o['Key'])
      end
    end
1219791
def cleanup(self):
        

        all([delete_file_or_tree(f) for f in self.to_delete])
        self.to_delete = []
347237
protected function cleanupOldChunks()
    {
        if ($this->useChunks === false) {
            // We have no write access. Do nothing.
            return;
        }

        static $beenHere = false;

        // We only do this once.
        if ($beenHere === true) {
            return;
        }

        $beenHere = true;
        // Clean up leftover files.
        $chunkList = glob($this->chunkDir . '*.Krexx.tmp');
        if (empty($chunkList) === false) {
            $now = time();
            foreach ($chunkList as $file) {
                // We delete everything that is older than 15 minutes.
                if (($this->pool->fileService->filetime($file) + 900) < $now) {
                    $this->pool->fileService->deleteFile($file);
                }
            }
        }
    }
321667
private static void deleteOldAndEmptyFiles() {
            File dir = LOG_FILE_DIR;
            if (dir.exists()) {
                File[] files = dir.listFiles();

                for (File f : files) {
                    if (f.length() == 0 ||
                            f.lastModified() + MAXFILEAGE < System.currentTimeMillis()) {
                        f.delete();
                    }
                }
            }
        }
5202
def delete_item(key):
    """"""
    CACHED_KEY_FILE = os.path.join(CURRENT_DIR, key)

    if os.path.isfile(CACHED_KEY_FILE):
        os.remove(CACHED_KEY_FILE)