Files do not exist while trying to purge trash
Symptoms
Error File does not exist is raised while trying to purge trash. The error shown is something like:
File does not exist: /home/openkm/tomcat-7.0.27/repository/datastore/4e/9c/ad/bb/4e9cadbb-2b8d-4e1b-8303-fbe09359300e
Cause
There are several reasons why you get this error:
- In a Linux scenario, OpenKM was started as the root user rather than the openkm user, and the files were created with incorrect permissions and now cannot be accessed by the openkm user.
- The file was accidentally removed from the server.
- Some older OpenKM versions were affected by a bug. The application in these versions did not remove document history files in the correct order, which caused this issue.
Solution
- Check at the OS level if the file exists. If the file exists:
- Check permissions; if they are wrong, correct them. If the permissions are correct, check if you have moved the repository.home location to another location (review OpenKM.cfg).
- If the file is not in the repository:
- Upgrade to the latest OpenKM version.
- Execute the script below
In the script there's a commented section that creates an empty missing file. We suggest first executing the script, checking the output (it also creates a log file named missing-*.log in the Tomcat logs folder), and finally uncommenting and executing it 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 |
|
Keywords
- AllVersions