Files does not exists while trying to purge trash

Symptons

Error File does not exists is raised while trying to purge trash. The error shown is something similar like:

File does not exists: /home/openkm/tomcat-7.0.27/repository/datastore/4e/9c/ad/bb/4e9cadbb-2b8d-4e1b-8303-fbe09359300e

Cause

There are several causes why you get this error:

  • In linux scenario, OpenKM has been started with root user rather openkm user and the files had been created with wrong grants and now is not able to being accessed by openkm user.
  • File has been removed accidentally from the server.
  • Some older OpenKM version were affected by a bug. The application in these versions does not remove history files of the document in the right order and that cause this issue.

Solution

  • Check at OS level if the file exists. In case file exist :
    • Check grants if are wrong correct them. In case grants are right check if you have moved the repository.home location to other ( review OpenKM.cfg ).
  • In case file is not into the repository:
    • Upgrade to the latest OpenKM version.
    • Execute the script below

In the script there's a commented section what creates an empty missing file. We suggest first execute the script, check the output ( also is create a file log name missing-*.log into the tomcat logs folder ) and finally uncomment and execute again.

import java.util.List;
import com.openkm.core.Config;
import com.openkm.dao.*;
import com.openkm.dao.bean.*;
import com.openkm.module.db.stuff.FsDataStore;
import com.openkm.util.*;
import com.openkm.api.*;
import com.openkm.bean.*;
import java.text.*;

private void checkFolder(String pathBase) {
	for (NodeBase node : NodeBaseDAO.getInstance().findByParent(pathBase, true, true, true, true, null)) {
		if (node instanceof NodeDocument) {
			boolean error = false;
			for (NodeDocumentVersion version : NodeDocumentVersionDAO.getInstance().findByParent(node.getUuid())) {
				// Check existence of each version
				File datastoreFile = FsDataStore.resolveFile(version.getUuid(), node.getTenant());
				if (!datastoreFile.exists()) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
					Document doc = OKMDocument.getInstance().getProperties(null, node.getUuid());
					String docPath = doc.getPath();
					String docName = PathUtils.getName(doc.getPath());
					String dateText = sdf.format(version.getCreated().getTime());
					String versionName = version.getName();
					String uuid = doc.getUuid();
					String dataStorePath = datastoreFile.getCanonicalPath();
					String msg = "<b>Path:</b>" + docPath + ", <b>Name:</b>" + docName + ", <b>date:</b>" + dateText
							+ ", <b>Version </b>" + versionName + ",<b> doc UUID:</b> " + uuid + ", <b>datastore path:</b>"
							+ dataStorePath;
					print(msg + "<br/>");

					// fileLogger.info(";"+docPath+";"+docName+";"+dateText+";"+versionName+";"+uuid+";"+dataStorePath);
					error = true;

					// Uncomment for creating missing files
					/*
					 * File file = new File(dataStorePath);
					 * file.getParentFile().mkdirs();
					 * FileWriter writer = new FileWriter(file);
					 */
				}
				
				if (error) {
					countBad++;
				} else {
					countGood++;
				}
			}
			
		} else {
			// Rest of the cases (NodeFolder, NodeMail, NodeRecord) --> search for children
			checkFolder(node.getUuid());
		}
	}
}

FileLogger fileLogger = new FileLogger("missing");
fileLogger.info("Starting evaluation");
int countBad = 0;
int countGood = 0;
//Path base where to init the checking
String pathBase = "/okm:root";
//this include the tenant checking.
String uuidBase = NodeBaseDAO.getInstance().getUuidFromPath(pathBase);

print("checking existence of documents in repository<br/>");

checkFolder(uuidBase);

print("Good:" +countGood + "<br/>");
print("Bad:" +countBad + "<br/>");
print("done");
fileLogger.info("Good:" +countGood);
fileLogger.info("Bad:" +countBad);
fileLogger.info("done");

Properties

Properties

Date

2018-03-03

Applies to

  • Core

Keywords

  • AllVersions
  •