Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions console/src/main/java/com/arcadedb/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ public Console setRootPath(final String rootDirectory) {

if (this.rootDirectory == null || this.rootDirectory.isEmpty())
this.rootDirectory = ".";
else if (this.rootDirectory.endsWith("/"))
else if (this.rootDirectory.endsWith(File.separator))
this.rootDirectory = this.rootDirectory.substring(0, this.rootDirectory.length() - 1);

if (!new File(this.rootDirectory + "/config").exists() && new File(this.rootDirectory + "/../config").exists()) {
databaseDirectory = new File(this.rootDirectory).getAbsoluteFile().getParentFile().getPath() + "/databases/";
if (!new File(this.rootDirectory + File.separator+ "config").exists() && new File(this.rootDirectory + File.separator + ".." +File.separator + "config").exists()) {
databaseDirectory = new File(this.rootDirectory).getAbsoluteFile().getParentFile().getPath() + File.separator+ "databases"+ File.separator;
} else
databaseDirectory = this.rootDirectory + "/databases/";
databaseDirectory = this.rootDirectory + File.separator+ "databases"+ File.separator;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DatabaseFactory(final String path) {
if (path == null || path.isEmpty())
throw new IllegalArgumentException("Missing path");

if (path.endsWith("/") || path.endsWith("\\"))
if (path.endsWith(File.separator))
databasePath = path.substring(0, path.length() - 1);
else
databasePath = path;
Expand All @@ -56,9 +56,9 @@ public synchronized void close() {
}

public boolean exists() {
boolean exists = new File(databasePath + "/" + EmbeddedSchema.SCHEMA_FILE_NAME).exists();
boolean exists = new File(databasePath + File.separator + EmbeddedSchema.SCHEMA_FILE_NAME).exists();
if (!exists)
exists = new File(databasePath + "/" + EmbeddedSchema.SCHEMA_PREV_FILE_NAME).exists();
exists = new File(databasePath + File.separator + EmbeddedSchema.SCHEMA_PREV_FILE_NAME).exists();
return exists;
}

Expand Down
13 changes: 8 additions & 5 deletions engine/src/main/java/com/arcadedb/database/EmbeddedDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@
public class EmbeddedDatabase extends RWLockContext implements DatabaseInternal {
public static final int EDGE_LIST_INITIAL_CHUNK_SIZE = 64;
public static final int MAX_RECOMMENDED_EDGE_LIST_CHUNK_SIZE = 8192;
private static final Set<String> SUPPORTED_FILE_EXT = Collections.unmodifiableSet(new HashSet<>(
Arrays.asList(Dictionary.DICT_EXT, Bucket.BUCKET_EXT, LSMTreeIndexMutable.NOTUNIQUE_INDEX_EXT, LSMTreeIndexMutable.UNIQUE_INDEX_EXT,
LSMTreeIndexCompacted.NOTUNIQUE_INDEX_EXT, LSMTreeIndexCompacted.UNIQUE_INDEX_EXT)));
private static final Set<String> SUPPORTED_FILE_EXT = Set.of(Dictionary.DICT_EXT,
Bucket.BUCKET_EXT,
LSMTreeIndexMutable.NOTUNIQUE_INDEX_EXT,
LSMTreeIndexMutable.UNIQUE_INDEX_EXT,
LSMTreeIndexCompacted.NOTUNIQUE_INDEX_EXT,
LSMTreeIndexCompacted.UNIQUE_INDEX_EXT);
public final AtomicLong indexCompactions = new AtomicLong();
protected final String name;
protected final PaginatedFile.MODE mode;
Expand Down Expand Up @@ -146,12 +149,12 @@ protected EmbeddedDatabase(final String path, final PaginatedFile.MODE mode, fin
this.statementCache = new StatementCache(this, configuration.getValueAsInteger(GlobalConfiguration.SQL_STATEMENT_CACHE));
this.executionPlanCache = new ExecutionPlanCache(this, configuration.getValueAsInteger(GlobalConfiguration.SQL_STATEMENT_CACHE));

if (path.endsWith("/") || path.endsWith("\\"))
if (path.endsWith(File.separator))
databasePath = path.substring(0, path.length() - 1);
else
databasePath = path;

configurationFile = new File(databasePath + "/configuration.json");
configurationFile = new File(databasePath + File.separator + "configuration.json");

final int lastSeparatorPos = path.lastIndexOf(File.separator);
if (lastSeparatorPos > -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void checkIntegrity() {
activeWALFilePool = new WALFile[walFiles.length];
for (int i = 0; i < walFiles.length; ++i) {
try {
activeWALFilePool[i] = new WALFile(database.getDatabasePath() + "/" + walFiles[i].getName());
activeWALFilePool[i] = new WALFile(database.getDatabasePath() + File.separator + walFiles[i].getName());
} catch (FileNotFoundException e) {
LogManager.instance().log(this, Level.SEVERE, "Error on WAL file management for file '%s'", e, database.getDatabasePath() + walFiles[i].getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.arcadedb.serializer.BinaryTypes;
import com.arcadedb.utility.RWLockContext;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.*;
Expand Down Expand Up @@ -463,7 +464,7 @@ protected LSMTreeIndexMutable splitIndex(final int startingFromPage, final LSMTr
final String newName = mutable.getName().substring(0, last_) + "_" + System.nanoTime();

final LSMTreeIndexMutable newMutableIndex = new LSMTreeIndexMutable(this, database, newName, mutable.isUnique(),
database.getDatabasePath() + "/" + newName, mutable.getKeyTypes(), pageSize, LSMTreeIndexMutable.CURRENT_VERSION, compactedIndex);
database.getDatabasePath() + File.separator + newName, mutable.getKeyTypes(), pageSize, LSMTreeIndexMutable.CURRENT_VERSION, compactedIndex);
database.getSchema().getEmbedded().registerFile(newMutableIndex);

final List<MutablePage> modifiedPages = new ArrayList<>(2 + mutable.getTotalPages() - startingFromPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.arcadedb.schema.Type;
import com.arcadedb.serializer.BinaryTypes;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -155,7 +156,7 @@ public LSMTreeIndexCompacted createNewForCompaction() throws IOException {
int last_ = name.lastIndexOf('_');
final String newName = name.substring(0, last_) + "_" + System.nanoTime();

return new LSMTreeIndexCompacted(mainIndex, database, newName, unique, database.getDatabasePath() + "/" + newName, binaryKeyTypes, pageSize);
return new LSMTreeIndexCompacted(mainIndex, database, newName, unique, database.getDatabasePath() + File.separator + newName, binaryKeyTypes, pageSize);
}

public IndexCursor iterator(final boolean ascendingOrder, final Object[] fromKeys, final boolean inclusive) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.arcadedb.query.sql.executor.ResultInternal;
import com.arcadedb.query.sql.executor.ResultSet;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Objects;
Expand All @@ -53,10 +54,10 @@ public ResultSet executeSimple(CommandContext ctx) {
result.setProperty("toUrl", targetUrl);

String fileName = targetUrl.startsWith("file://") ? targetUrl.substring("file://".length()) : targetUrl;
if (fileName.contains("..") || fileName.contains("/") || fileName.contains("\\"))
if (fileName.contains("..") || fileName.contains(File.separator) )
throw new IllegalArgumentException("Export file cannot contain path change because the directory is specified");

fileName = "exports/" + fileName;
fileName = "exports" + File.separator + fileName;

try {
final Class<?> clazz = Class.forName("com.arcadedb.integration.exporter.Exporter");
Expand Down
18 changes: 9 additions & 9 deletions engine/src/main/java/com/arcadedb/schema/EmbeddedSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public EmbeddedSchema(final DatabaseInternal database, final String databasePath

indexFactory.register(INDEX_TYPE.LSM_TREE.name(), new LSMTreeIndex.IndexFactoryHandler());
indexFactory.register(INDEX_TYPE.FULL_TEXT.name(), new LSMTreeFullTextIndex.IndexFactoryHandler());
configurationFile = new File(databasePath + "/" + SCHEMA_FILE_NAME);
configurationFile = new File(databasePath + File.separator + SCHEMA_FILE_NAME);
}

@Override
Expand Down Expand Up @@ -268,7 +268,7 @@ public Bucket createBucket(final String bucketName, final int pageSize) {

return recordFileChanges(() -> {
try {
final Bucket bucket = new Bucket(database, bucketName, databasePath + "/" + bucketName, PaginatedFile.MODE.READ_WRITE, pageSize,
final Bucket bucket = new Bucket(database, bucketName, databasePath + File.separator + bucketName, PaginatedFile.MODE.READ_WRITE, pageSize,
Bucket.CURRENT_VERSION);
registerFile(bucket);
bucketMap.put(bucketName, bucket);
Expand Down Expand Up @@ -605,7 +605,7 @@ protected Index createBucketIndex(final DocumentType type, final Type[] keyTypes
if (indexMap.containsKey(indexName))
throw new DatabaseMetadataException("Cannot create index '" + indexName + "' on type '" + typeName + "' because it already exists");

final IndexInternal index = indexFactory.createIndex(indexType.name(), database, indexName, unique, databasePath + "/" + indexName,
final IndexInternal index = indexFactory.createIndex(indexType.name(), database, indexName, unique, databasePath + File.separator + indexName,
PaginatedFile.MODE.READ_WRITE, keyTypes, pageSize, nullStrategy, callback);

try {
Expand Down Expand Up @@ -636,7 +636,7 @@ public Index createManualIndex(final INDEX_TYPE indexType, final boolean unique,
database.transaction(() -> {

final IndexInternal index = indexFactory.createIndex(indexType.name(), database, FileUtils.encode(indexName, ENCODING), unique,
databasePath + "/" + indexName, PaginatedFile.MODE.READ_WRITE, keyTypes, pageSize, nullStrategy, null);
databasePath + File.separator + indexName, PaginatedFile.MODE.READ_WRITE, keyTypes, pageSize, nullStrategy, null);

result.set(index);

Expand Down Expand Up @@ -1073,9 +1073,9 @@ protected synchronized void readConfiguration() {

boolean saveConfiguration = false;
try {
File file = new File(databasePath + "/" + SCHEMA_FILE_NAME);
File file = new File(databasePath + File.separator + SCHEMA_FILE_NAME);
if (!file.exists() || file.length() == 0) {
file = new File(databasePath + "/" + SCHEMA_PREV_FILE_NAME);
file = new File(databasePath + File.separator + SCHEMA_PREV_FILE_NAME);
if (!file.exists())
return;

Expand Down Expand Up @@ -1298,7 +1298,7 @@ public synchronized void saveConfiguration() {
dirtyConfiguration = false;

} catch (IOException e) {
LogManager.instance().log(this, Level.SEVERE, "Error on saving schema configuration to file: %s", e, databasePath + "/" + SCHEMA_FILE_NAME);
LogManager.instance().log(this, Level.SEVERE, "Error on saving schema configuration to file: %s", e, databasePath + File.separator + SCHEMA_FILE_NAME);
}
}

Expand Down Expand Up @@ -1393,7 +1393,7 @@ public synchronized void update(final JSONObject newSchema) throws IOException {
final String latestSchema = newSchema.toString();

if (configurationFile.exists()) {
final File copy = new File(databasePath + "/" + SCHEMA_PREV_FILE_NAME);
final File copy = new File(databasePath + File.separator + SCHEMA_PREV_FILE_NAME);
if (copy.exists())
if (!copy.delete())
LogManager.instance().log(this, Level.WARNING, "Error on deleting previous schema file '%s'", null, copy);
Expand All @@ -1402,7 +1402,7 @@ public synchronized void update(final JSONObject newSchema) throws IOException {
LogManager.instance().log(this, Level.WARNING, "Error on renaming previous schema file '%s'", null, copy);
}

try (FileWriter file = new FileWriter(databasePath + "/" + SCHEMA_FILE_NAME)) {
try (FileWriter file = new FileWriter(databasePath + File.separator + SCHEMA_FILE_NAME)) {
file.write(latestSchema);
}

Expand Down
4 changes: 2 additions & 2 deletions engine/src/main/java/com/arcadedb/utility/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static String getSizeAsString(final long iSize) {
}

public static void checkValidName(final String iFileName) throws IOException {
if (iFileName.contains("..") || iFileName.contains("/") || iFileName.contains("\\"))
if (iFileName.contains("..") || iFileName.contains(File.separator))
throw new IOException("Invalid file name '" + iFileName + "'");
}

Expand Down Expand Up @@ -240,7 +240,7 @@ public static final void copyDirectory(final File source, final File destination
destination.mkdirs();

for (File f : source.listFiles()) {
final File target = new File(destination.getAbsolutePath() + "/" + f.getName());
final File target = new File(destination.getAbsolutePath() + File.separator + f.getName());
if (f.isFile())
copyFile(f, target);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.arcadedb.integration.backup;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void validateSettings() {

if (directory != null && file != null) {
final String f = file.startsWith("file://") ? file.substring("file://".length()) : file;
if (f.contains("..") || f.contains("/"))
if (f.contains("..") || f.contains(File.separator))
throw new IllegalArgumentException("Backup file cannot contain path change because the directory is specified");
}

Expand All @@ -70,7 +71,7 @@ public int parseParameter(final String name, final String value) {
format = value.toLowerCase();
} else if ("dir".equals(name)) {
if (value != null)
directory = value.endsWith("/") ? value : value + "/";
directory = value.endsWith(File.separator) ? value : value + File.separator;
} else if ("f".equals(name)) {
if (value != null)
file = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void backupDatabase() throws Exception {
fileName = settings.file;

if (settings.directory != null)
fileName = settings.directory + "/" + fileName;
fileName = settings.directory + File.separator + fileName;

final File backupFile = new File(fileName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.arcadedb.integration.restore;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -69,7 +70,7 @@ public void validate() {
if (databaseDirectory == null)
throw new IllegalArgumentException("Missing database url. Use -d <database-directory>");

if (inputFileURL.contains("..") || inputFileURL.startsWith("/"))
if (inputFileURL.contains("..") || inputFileURL.startsWith(File.separator))
throw new IllegalArgumentException("Invalid backup file: cannot contain '..' or start with '/'");
}
}
8 changes: 4 additions & 4 deletions server/src/main/java/com/arcadedb/server/ArcadeDBServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public synchronized DatabaseInternal createDatabase(final String databaseName) {
throw new IllegalArgumentException("Database '" + databaseName + "' already exists");

final DatabaseFactory factory = new DatabaseFactory(
configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + "/" + databaseName).setAutoTransaction(true);
configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + File.separator + databaseName).setAutoTransaction(true);

if (factory.exists())
throw new IllegalArgumentException("Database '" + databaseName + "' already exists");
Expand Down Expand Up @@ -347,7 +347,7 @@ public synchronized Database getDatabase(final String databaseName, final boolea
if (!allowLoad)
throw new DatabaseIsClosedException("Database '" + databaseName + "' is not available");

final String path = configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + "/" + databaseName;
final String path = configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + File.separator + databaseName;

final DatabaseFactory factory = new DatabaseFactory(path).setAutoTransaction(true);

Expand Down Expand Up @@ -422,7 +422,7 @@ private void loadDefaultDatabases() {
((DatabaseInternal) database).getEmbedded().drop();
databases.remove(dbName);
}
String dbPath = configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + "/" + dbName;
String dbPath = configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + File.separator + dbName;
// new Restore(commandParams, dbPath).restoreDatabase();

try {
Expand Down Expand Up @@ -508,7 +508,7 @@ private void parseCredentials(final String dbName, final String credentials) {
}

private void loadConfiguration() {
final File file = new File(getRootPath() + "/" + CONFIG_SERVER_CONFIGURATION_FILENAME);
final File file = new File(getRootPath() + File.separator + CONFIG_SERVER_CONFIGURATION_FILENAME);
if (file.exists()) {
try {
final String content = FileUtils.readFileAsString(file, "UTF8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.arcadedb.utility.FileUtils;
import com.arcadedb.utility.Pair;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.SocketTimeoutException;
Expand Down Expand Up @@ -412,7 +413,7 @@ private void installDatabase(final Binary buffer, final String db, final Databas
throws IOException {

// WRITE THE SCHEMA
try (final FileWriter schemaFile = new FileWriter(database.getDatabasePath() + "/" + EmbeddedSchema.SCHEMA_FILE_NAME,
try (final FileWriter schemaFile = new FileWriter(database.getDatabasePath() + File.separator + EmbeddedSchema.SCHEMA_FILE_NAME,
DatabaseFactory.getDefaultCharset())) {
schemaFile.write(dbStructure.getSchemaJson());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.arcadedb.server.ha.ReplicationException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void updateFiles(final DatabaseInternal db) throws IOException {

// ADD FILES
for (Map.Entry<Integer, String> entry : filesToAdd.entrySet())
db.getFileManager().getOrCreateFile(entry.getKey(), databasePath + "/" + entry.getValue());
db.getFileManager().getOrCreateFile(entry.getKey(), databasePath + File.separator + entry.getValue());

// REMOVE FILES
for (Map.Entry<Integer, String> entry : filesToRemove.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public DatabaseStructureRequest(final String dbName) {
public HACommand execute(final HAServer server, final String remoteServerName, final long messageNumber) {
final DatabaseInternal db = (DatabaseInternal) server.getServer().getDatabase(databaseName);

final File file = new File(db.getDatabasePath() + "/" + EmbeddedSchema.SCHEMA_FILE_NAME);
final File file = new File(db.getDatabasePath() + File.separator + EmbeddedSchema.SCHEMA_FILE_NAME);
try {
final String schemaJson;
if (file.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.arcadedb.server.ha.ReplicationException;
import com.arcadedb.utility.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;

Expand Down Expand Up @@ -76,7 +77,7 @@ public HACommand execute(final HAServer server, final String remoteServerName, f
final PageManager pageManager = database.getPageManager();

try {
final PaginatedFile file = database.getFileManager().getOrCreateFile(fileId, database.getDatabasePath() + "/" + fileName);
final PaginatedFile file = database.getFileManager().getOrCreateFile(fileId, database.getDatabasePath() + File.separator + fileName);

if (totalPages == 0)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class SecurityGroupFileRepository {
private Callable<Void, JSONObject> reloadCallback = null;

public SecurityGroupFileRepository(String securityConfPath) {
if (!securityConfPath.endsWith("/") && !securityConfPath.endsWith("\\"))
securityConfPath += "/";
if (!securityConfPath.endsWith(File.separator))
securityConfPath += File.separator;
this.securityConfPath = securityConfPath;
file = new File(securityConfPath, FILE_NAME);
}
Expand Down
Loading