Delete obsolete log files, which is by default 2 days.
499082
public static void cleanObsolete() {
        HandlerThreadFactory.getWriteLogThreadHandler().post(new Runnable() {
            @Override
            public void run() {
                long now = System.currentTimeMillis();
                File[] f = BlockCanaryInternals.getLogFiles();
                if (f != null && f.length > 0) {
                    synchronized (SAVE_DELETE_LOCK) {
                        for (File aF : f) {
                            if (now - aF.lastModified() > OBSOLETE_DURATION) {
                                aF.delete();
                            }
                        }
                    }
                }
            }
        });
    }
599307
public static function removeOldFiles() {
		
		if (!is_dir(static::TEMP_FOLDER)) {
			return;
		}
		
		$app = Application::getInstance();
		$counter = 0;

		$files = Utilities::getDirectoryFilenames(static::TEMP_FOLDER);

		foreach ($files as $file) {

			$pathFile	= APPLICATION_PATH . '/' .static::TEMP_FOLDER . '/' . $file;
			$fileLife	= time() - filemtime($pathFile);
			$maxLife	= static::FILE_EXPIRE * 60;
			
			if ($fileLife > $maxLife) {
				$counter++;
				unlink($pathFile);
			}

		}
		
		if ($counter) {
			$app->logEvent($counter . ' files has been deleted from ' . static::TEMP_FOLDER);
		} else {
			$app->logEvent('No old files deleted from ' . static::TEMP_FOLDER);
		}
		
	}
1125469
public function clearExpired()
    {
        if (! $this->enabled) {
            return;
        }
        $error = false;

        set_error_handler(function () use (&$error) {
            $error = true;
        }, E_WARNING);
        foreach (glob($this->getPath() . '/*.dat') as $file) {
            if (filemtime($file) < time()) {
                unlink($file);
            }
        }
        restore_error_handler();

        return ! $error;
    }
1041929
public static function clear(): void
    {
        $log_file =
            Plugin::dataPath().
            DIRECTORY_SEPARATOR."plugin.log";

        if(!file_exists(dirname($log_file)))
            mkdir(dirname($log_file));

        file_put_contents(
            $log_file,
            "",
            LOCK_EX
        );
    }
1002626
protected void cleanupSfDumps(boolean deleteOldest)
  {
    // Check what the maximum number of dumpfiles and the max allowable
    // aggregate dump file size is.
    int maxDumpFiles =
        System.getProperty(MAX_NUM_DUMP_FILES_PROP) != null ?
        Integer.valueOf(System.getProperty(MAX_NUM_DUMP_FILES_PROP)) :
        DEFAULT_MAX_DUMP_FILES;

    int maxDumpDirSizeMB =
        System.getProperty(MAX_SIZE_DUMPS_MB_PROP) != null ?
        Integer.valueOf(System.getProperty(MAX_SIZE_DUMPS_MB_PROP)) :
        DEFAULT_MAX_DUMPDIR_SIZE_MB;

    File dumpDir = new File(logDumpPathPrefix);
    long dirSizeBytes = 0;

    if (dumpDir.listFiles() == null)
    {
      return;
    }

    // Keep a sorted list of files by size as we go in case we need to
    // delete some
    TreeSet<File> fileList =
        new TreeSet<>(new Comparator<File>()
        {
          @Override
          public int compare(File a, File b)
          {
            return a.length() < b.length() ? -1 : 1;
          }
        });

    // Loop over files in this directory and get rid of old ones
    // while accumulating the total size
    for (File file : dumpDir.listFiles())
    {
      if ((!file.getName().startsWith(LOG_DUMP_FILE_NAME) &&
           !file.getName().startsWith(IncidentUtil.INC_DUMP_FILE_NAME)) ||
          (System.currentTimeMillis() - file.lastModified() > FILE_EXPN_TIME_MS &&
           file.delete()))
      {
        continue;
      }

      dirSizeBytes += file.length();
      fileList.add(file);
    }

    // If we're exceeding our max allotted disk usage, cut some stuff out;
    // else if we need to make space for a new dump delete the oldest.
    if (dirSizeBytes >= ((long) maxDumpDirSizeMB << 20))
    {
      // While we take up more than half the allotted disk usage, keep deleting.
      for (File file : fileList)
      {
        if (dirSizeBytes < ((long) maxDumpDirSizeMB << 19))
        {
          break;
        }

        long victimSize = file.length();
        if (file.delete())
        {
          dirSizeBytes -= victimSize;
        }
      }
    }
    else if (deleteOldest && fileList.size() >= maxDumpFiles)
    {
      fileList.first().delete();
    }
  }
247673
protected void cleanOutOldAvatars(File directory, int maxLifeInDays){
        if (directory != null){
            if (mCleanedDirectories.contains(directory.getAbsolutePath())){
                return;
            }
            long oldestTimeAllowed = System.currentTimeMillis() - maxLifeInDays * TimeUnit.DAYS.toMillis(maxLifeInDays);
            File[] files = directory.listFiles();
            if (files != null){
                for (File file : files){
                    if (file.getName().startsWith(DEFAULT_AVATAR_FILE_PREFIX) && file.lastModified() < oldestTimeAllowed){
                        file.delete();
                    }
                }
            }
        }
    }
1354551
private function cleanTarget(): void
    {
        foreach ($this->targetDictionary->keys() as $key) {
            if (!$this->sourceDictionary->has($key) || $this->sourceDictionary->get($key)->isSourceEmpty()) {
                $this->logger->log($this->logLevel, 'Removing obsolete {key}.', ['key' => $key]);
                if ($this->dryRun) {
                    continue;
                }

                $this->targetDictionary->remove($key);
            }
        }
    }
1219791
def cleanup(self):
        

        all([delete_file_or_tree(f) for f in self.to_delete])
        self.to_delete = []
899597
public function removeAssets()
    {
        // Base implementation does only know about log file.
        if ($this->logFile) {
            if (file_exists($this->logFile)) {
                unlink($this->logFile);
            }
            $this->logFile = null;
            $this->file->remove('log');
        }
    }
746432
def purge_old_event_logs(delete_before_days=7):
    
    delete_before_date = timezone.now() - timedelta(days=delete_before_days)
    logs_deleted = EventLog.objects.filter(
        created_on__lte=delete_before_date).delete()
    return logs_deleted
1204059
public function cleanUp()
    {
        $this->filesystem->remove($this->compressedArchivePath);
        $this->filesystem->remove($this->outputPath);
    }
252655
def _cleanup(self):
        """"""
        self._expkg = None
        self._extmp = None
        self._flag_e = True
        self._ifile.close()
183211
private void removeOldFiles()
    {
        if (_retainDays>0)
        {
            Calendar retainDate = Calendar.getInstance();
            retainDate.add(Calendar.DATE,-_retainDays);
            int borderYear = retainDate.get(java.util.Calendar.YEAR);
            int borderMonth = retainDate.get(java.util.Calendar.MONTH) + 1;
            int borderDay = retainDate.get(java.util.Calendar.DAY_OF_MONTH);

            File file= new File(_filename);
            File dir = new File(file.getParent());
            String fn=file.getName();
            int s=fn.toLowerCase().indexOf(YYYY_MM_DD);
            if (s<0)
                return;
            String prefix=fn.substring(0,s);
            String suffix=fn.substring(s+YYYY_MM_DD.length());

            String[] logList=dir.list();
            for (int i=0;i<logList.length;i++)
            {
                fn = logList[i];
                if(fn.startsWith(prefix)&&fn.indexOf(suffix,prefix.length())>=0)
                {        
                    try
                    {
                        StringTokenizer st = new StringTokenizer (fn.substring(prefix.length(), prefix.length()+YYYY_MM_DD.length()), "_.");
                        int nYear = Integer.parseInt(st.nextToken());
                        int nMonth = Integer.parseInt(st.nextToken());
                        int nDay = Integer.parseInt(st.nextToken());
                        
                        if (nYear<borderYear ||
                            (nYear==borderYear && nMonth<borderMonth) ||
                            (nYear==borderYear &&
                             nMonth==borderMonth &&
                             nDay<=borderDay))
                        {
                            log.info("Log age "+fn);
                            new File(dir,fn).delete();
                        }
                    }
                    catch(Exception e)
                    {
                        if (log.isDebugEnabled())
                            e.printStackTrace();
                    }
                }
            }
        }
    }
1373632
def clear_logfile(logfile):
    
    try:
        os.remove(logfile + '_out.txt')
    except IOError:
        pass
    try:
        os.remove(logfile + '_err.txt')
    except IOError:
        pass
721621
public function purgeAll() {
		if ($this->log) {
			if ($this->log instanceof LoggerInterface) {
				$this->log->info("Purging the whole file cache.");
			} else {
				$this->log->trace("Purging the whole file cache.");
			}
		}
		$files = glob($this->getDirectory()."*");
        if (false !== $files){// some file systems wont distinguish between empty match and an error
            $prefixFile = str_replace(array("_", "/", "\\", ":"), array("___", "_s_", "_b_", "_d_"), $this->prefix);
            foreach ($files as $filename) {
                if (empty($prefixFile) || strpos(basename($filename), $prefixFile) === 0) {
                    unlink($filename);
                }
            }
        }
	}
922971
def cleanup(self):
        """"""
        expires = maybe_timedelta(self.expires)
        for model in self.TaskModel, self.TaskSetModel:
            model._default_manager.delete_expired(expires)
194132
def purge_old_logs(delete_before_days=7):
    
    delete_before_date = timezone.now() - timedelta(days=delete_before_days)
    logs_deleted = Log.objects.filter(
        created_on__lte=delete_before_date).delete()
    return logs_deleted