public dillResult renameFile(long fileId, String name) {
boolean dohdfs = false;
boolean dodelete = false;
boolean doinsert = false;
dillResult result = new dillResult();
HdfsFile file = filedao.findFile(fileId);
String src = file.getFileUrl();// 源url
String dst = src.substring(0, src.lastIndexOf("/")) + "/" + name;// 新的url
System.out.println("the new name is:" + dst);
renameAction rename = new renameAction();
try {
dohdfs = rename.rename(src, dst);// 操作文件系统
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//
if (dohdfs) {
System.out.println("do hdfs success!");
filedao.deleteFiles(file.getFileUrl());// 删除原来的记录
dodelete = true;
}
if (dodelete) {
System.out.println("do delete success!");
long newid = pathToId.ParsepathToId(dst);// 获得新的fileid
file.setFileId(newid);
file.setFileName(name);
file.setFileUrl(dst);
doinsert = filedao.insertFile(file);// 新增记录
}
if (doinsert) {
System.out.println("do insert success");
String listfile = listFile(file.getParentid(), file.getUserId());
result.setWddescjson(listfile);
result.setUserId(file.getUserId());
result.setParentid(file.getParentid());
// result.setFileName(name);
result.setFileUrl(dst);
System.out.println("the new name is:" + dst);
}