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-01-09 05:15] 91.8.36.67install: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. 
 + 
 +Alternatively the [[plugin:removeold|removeold Plugin]] can be used.
  
-==== 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 19: 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):
  
 <code> <code>
-grep -Ev '^($|#)' /tmp/removeold.txt | xargs -n 1 rm -fr+grep -Ev '^($|#)' data/deleted.files | xargs -n 1 rm -fr
 </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 33: 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 60: Line 102:
 </code>  </code> 
  
-=== PHP Script ===+==== PHP Script ====
  
 The same for PHP: The same for PHP:
 <code php> <code php>
 <?php <?php
-/* Security function, uncomment to "active" the script. */ +/* Security function, comment this out to "activate" the script. */ 
-//exit('Check source');+exit('Check source');
  
 $path = getcwd(); $path = getcwd();
Line 83: 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 91: Line 133:
 </code> </code>
  
-==== RemoveOld Plugin ====+==== CMD Script ====
  
-To remove old files from DokuWiki'Admin menu you can also use the [[plugin:RemoveOld]] plugin.+Here'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.1389240949.txt.gz · Last modified: 2014-01-09 05:15 by 91.8.36.67

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