DokuWiki

It's better when it's simple

User Tools

Site Tools


install:unused_files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
install:unused_files [2014-10-14 15:29] – [Removing Unused Files] 80.187.111.87install:unused_files [2023-02-28 13:41] (current) – Link to new dokuwiki repo saggi
Line 1: Line 1:
-===== Removing Unused Files =====+====== 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.+When a new DokuWiki version is released, some of the files that were needed previously may become obsolete. 
 + 
 +Keeping the files may cause the following issues: 
 + 
 +  * Misleading error messages related to outdated plugins. 
 +  * They pose a security risk
 +  * They could break later installations. 
 + 
 +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. 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+You can also see the current list at https://github.com/dokuwiki/dokuwiki/raw/stable/data/deleted.files 
 + 
 +:!: Important: The list of files is case-sensitive. On case-insensitive file systems((Case-insensitive file systems are, under some circumstances: Windows and macOS)) the scripts below may delete too much! 
 + 
 +===== Using a Plugin ===== 
 + 
 +When upgrading your wiki using the [[plugin:upgrade|upgrade Plugin]], the plugin will take care of removing the deleted files automatically for you.
  
-==== Using RemoveOld Plugin ====+Alternatively the [[plugin:removeold|removeold Plugin]] can be used.
  
-To remove old files from DokuWiki's Admin menu you can also use the [[plugin:RemoveOld]] plugin. +===== Using a Script =====
-==== Using a Script ====+
  
 People with shell access to their server can use a script to automatically delete all old files. People with shell access to their server can use a script to automatically delete all old files.
  
-=== Linux Shell ===+==== Linux Shell ====
  
 This simple line should work on any Linux system This simple line should work on any Linux system
Line 22: Line 35:
 </code> </code>
  
-=== *nix Shell ===+==== *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): 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):
Line 30: Line 43:
 </code> </code>
  
-=== Python Script ===+==== Python Script ====
  
 Here's a Python script that will also print the files deleted Here's a Python script that will also print the files deleted
Line 36: Line 49:
 <code python> <code python>
 import os import os
-file = open("./data/deleted.files") +for line in open("./data/deleted.files"): 
-for line in file: +    if line.isspace() or line[0] == '#': 
-        #os.remove(line) +        continue 
-    if not line.isspace() +    line = line.rstrip(os.linesep) 
- if not line[0:1] =='#'  +    try: 
-  line = line.rstrip(os.linesep) +        if os.path.exists(line): 
- try: +            print('File removed =>  ' + line) 
-   if(os.path.exists(line)): +            os.remove(line) 
-     print('File removed =>  ' + line) +    except OSError: 
-         os.remove(line) +        pass
- except OSError, err+
- pass+
 </code> </code>
  
-=== Ruby Script ===+Here's an alternative Python script that is case sensitive and will also delete directories included in the list 
 +<code python> 
 +import os 
 +import shutil 
 + 
 +def exists_casesensitive(path): 
 +    if not os.path.exists(path): 
 +        return False 
 +    directory, filename = os.path.split(path) 
 +    return filename in os.listdir(directory) 
 + 
 +with open("./data/deleted.files") as file: 
 +    for line in file: 
 +        line = line.strip() 
 +        if line and not line.startswith('#'): 
 +            path = line.rstrip(os.linesep) 
 +            if exists_casesensitive(path): 
 +                if os.path.isdir(path): 
 +                    shutil.rmtree(path) 
 +                    print('Directory removed =>  ' + path) 
 +                else: 
 +                    os.remove(path) 
 +                    print('File removed =>  ' + path) 
 +            else: 
 +                #print('File not found => ' + path) 
 +                pass 
 +</code> 
 + 
 +==== Ruby Script ====
  
 Here's a Ruby script doing the same Here's a Ruby script doing the same
Line 63: Line 102:
 </code>  </code> 
  
-=== PHP Script ===+==== PHP Script ====
  
 The same for PHP: The same for PHP:
Line 86: Line 125:
 </code> </code>
  
-=== Powershell Script ===+==== Powershell Script ====
  
 Here's a one-line powershell script doing the same Here's a one-line powershell script doing the same
Line 94: Line 133:
 </code> </code>
  
 +==== 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.
 +
 +<code>
 +for /F %i in ('findstr /R /V /C:"^#" /C:"^$" data\deleted.files') do del "%i"
 +</code>
install/unused_files.1413293380.txt.gz · Last modified: 2014-10-14 15:29 by 80.187.111.87

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