/
Check.java
41 lines (35 loc) · 1.09 KB
/
Check.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.basex.core.cmd;
import org.basex.core.*;
import org.basex.io.*;
/**
* Evaluates the 'check' command: opens an existing database or
* creates a new one.
*
* @author BaseX Team 2005-12, BSD License
* @author Christian Gruen
*/
public final class Check extends ACreate {
/**
* Default constructor.
* @param path file path
*/
public Check(final String path) {
super(path);
}
@Override
protected boolean run() {
// close existing database
new Close().run(context);
// get path and database name
final QueryInput qi = new QueryInput(args[0]);
qi.db = qi.io.dbname();
// choose OPEN if user has no create permissions, or if database exists
final boolean create = context.user.has(Perm.CREATE);
final Command cmd = progress(!create || mprop.dbpath(qi.db).exists() ?
new Open(qi.db) : new CreateDB(qi.db, qi.io.exists() ? qi.original : null));
// execute command
final boolean ok = cmd.run(context);
final String msg = cmd.info().trim();
return ok ? info(msg) : error(msg);
}
}