DokuWiki

It's better when it's simple

User Tools

Site Tools


install:unused_files

This is an old revision of the document!


Removing Unused Files

When a new DokuWiki version is released, some of the files that were needed previously may become obsolete. Keeping these files is harmless usually but they might pose a security risk or break installations later, so we recommend to delete them.

A list of all files that were removed in recent releases can be found in data/deleted.files. You should check if they still exist in your install. If they do, delete them.

You can also see the current list at https://github.com/splitbrain/dokuwiki/raw/stable/data/deleted.files

:!: Important the list of files is case-sensitive. On case-insensitive file systems the scripts below may delete too much!

Using a Script

People with shell access to their server can use a script to automatically delete all old files.

Linux Shell

This simple line should work on any Linux system

grep -Ev '^($|#)' data/deleted.files | xargs -n 1 rm -vf

*nix Shell

Some systems may not support the “rm -d” option for directory removal. In that case, you have to use recursive removal (just be sure to double-check that the file list does not include any paths that will delete too much):

grep -Ev '^($|#)' data/deleted.files | xargs -n 1 rm -fr

Python Script

Here's a Python script that will also print the files deleted

import os
for line in open("./data/deleted.files"):
    if line.isspace() or line[0] == '#':
        continue
    line = line.rstrip(os.linesep)
    try:
        if os.path.exists(line):
            print('File removed =>  ' + line)
            os.remove(line)
    except OSError:
        pass

Ruby Script

Here's a Ruby script doing the same

files = File.read("./data/deleted.files").split("\n").grep(/^[^$#]/)
 
files.each do |file|
  puts "Deleting #{file}."
  File.delete(file) rescue puts $!
end

PHP Script

The same for PHP:

<?php
/* Security function, comment this out to "activate" the script. */
exit('Check source');
 
$path = getcwd();
 
if(file_exists($path . '/data/deleted.files')) {
  $file = fopen($path . '/data/deleted.files', 'r');
  while(false !== ($line = fgets($file))) {
    $line = trim($line);
    if(!empty($line) && !preg_match('/^\#/', $line) && file_exists($path . '/' . $line)) {
      unlink($path . '/' . $line);
      echo '/' . $line . ' - deleted<br/>';
    }
  }
  echo 'Done!';
}

Powershell Script

Here's a one-line powershell script doing the same

Get-Content .\data\deleted.files | Where-Object {$_ -notmatch '^($|#)' -and (Test-Path $_ )} | Foreach-Object {Remove-Item -path $_ -Force -Recurse}

CMD Script

Here's a one-line Windows's CMD script doing the same, although you may need to first reverse all the slashes in 'deleted.files' for the filenames to be accepted.

for /F %i in ('findstr /R /V /C:"^#" /C:"^$" data\deleted.files') do del "%i"
install/unused_files.1525341483.txt.gz · Last modified: 2018-05-03 11:58 by andi

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki