}
DB db = Configuration.getMongo().getDB(
Configuration.getProperty("mongo.db"));
V7GridFS fs = new V7GridFS(db);
if ("-sha".equals(args[1])) {
MongoContentStorage storage = new MongoContentStorage(db);
String sha = args[2];
try {
ContentSHA file = findContentByPrefix(storage, sha);
if (file == null)
throw new FileNotFoundException("-sha " + sha);
String[] path = getPath(args[3], args[4]);
createFile(fs, file, path, null);
} catch (DecoderException e) {
throw new IllegalArgumentException("invalid parameter :" + sha
+ " is not a hex-encoded SHA-1 prefix");
}
} else {
String[] srcPath = getPath(args[1], args[2]);
String[] targetPath = getPath(args[3], args[4]);
V7File src = fs.getFile(srcPath);
if (src == null) {
throw new FileNotFoundException(args[1] + " " + args[2]);
}
if (src.hasContent()) {
createFile(fs, src.getContentPointer(), targetPath, src
.getContentType());
} else {
V7File existing = fs.getFile(targetPath);
if (existing != null) {
throw new IOException("copy target " + targetPath
+ " already exists");
}
V7File parent = getParent(fs, targetPath);