use of diskCacheV111.vehicles.PnfsRenameMessage in project dcache by dCache.
the class PnfsManagerTest method testMoveEntry.
@Test
public void testMoveEntry() throws Exception {
PnfsCreateEntryMessage message = new PnfsCreateEntryMessage("/pnfs/testRoot/testMoveEntry", FileAttributes.ofFileType(DIR));
_pnfsManager.createEntry(message);
assertTrue("failed to create a directory", message.getReturnCode() == 0);
FsInode srcInode = _fs.mkdir("/pnfs/testRoot/testMoveEntry/sourceDirectory");
byte[] srcTagData = "foo".getBytes();
_fs.setTag(srcInode, "sGroup", srcTagData, 0, srcTagData.length);
FsInode dstInode = _fs.mkdir("/pnfs/testRoot/testMoveEntry/destinationDirectory");
byte[] dstTagData = "bar".getBytes();
_fs.setTag(dstInode, "sGroup", dstTagData, 0, dstTagData.length);
message = new PnfsCreateEntryMessage("/pnfs/testRoot/testMoveEntry/sourceDirectory/sourceFile", FileAttributes.ofFileType(REGULAR));
_pnfsManager.createEntry(message);
assertTrue("failed to create an entry", message.getReturnCode() == 0);
PnfsRenameMessage pnfsRenameMessage = new PnfsRenameMessage("/pnfs/testRoot/testMoveEntry/sourceDirectory/sourceFile", "/pnfs/testRoot/testMoveEntry/destinationDirectory/destinationFile", false);
_pnfsManager.rename(pnfsRenameMessage);
assertTrue("failed to move file to directory", pnfsRenameMessage.getReturnCode() == 0);
ChimeraNameSpaceProvider provider = (ChimeraNameSpaceProvider) _pnfsManager.getNameSpaceProvider();
provider.setAllowMoveToDirectoryWithDifferentStorageClass(false);
pnfsRenameMessage = new PnfsRenameMessage("/pnfs/testRoot/testMoveEntry/destinationDirectory/destinationFile", "/pnfs/testRoot/testMoveEntry/sourceDirectory/sourceFile", false);
_pnfsManager.rename(pnfsRenameMessage);
assertTrue("succeeded to move file to directory with different tag, a failure", pnfsRenameMessage.getReturnCode() != 0);
pnfsRenameMessage = new PnfsRenameMessage("/pnfs/testRoot/testMoveEntry/destinationDirectory", "/pnfs/testRoot/testMoveEntry/sourceDirectory/destinationDirectory", false);
_pnfsManager.rename(pnfsRenameMessage);
assertTrue("succeeded to move directory to directory with different tag, a failure", pnfsRenameMessage.getReturnCode() != 0);
}
use of diskCacheV111.vehicles.PnfsRenameMessage in project dcache by dCache.
the class PnfsManagerV3 method rename.
public void rename(PnfsRenameMessage msg) {
try {
checkMask(msg);
PnfsId pnfsId = msg.getPnfsId();
String sourcePath = msg.getPnfsPath();
String destinationPath = msg.newName();
// This case is for compatibility with versions before 2.14
if (sourcePath == null) {
if (pnfsId == null) {
throw new InvalidMessageCacheException("Either path or pnfs id is required.");
}
sourcePath = _nameSpaceProvider.pnfsidToPath(msg.getSubject(), pnfsId);
}
LOGGER.info("Rename {} to new name: {}", sourcePath, destinationPath);
checkRestriction(msg, MANAGE, FsPath.create(sourcePath).parent());
checkRestriction(msg, MANAGE, FsPath.create(destinationPath).parent());
boolean overwrite = msg.getOverwrite() && !msg.getRestriction().isRestricted(DELETE, FsPath.create(destinationPath));
_nameSpaceProvider.rename(msg.getSubject(), pnfsId, sourcePath, destinationPath, overwrite);
} catch (CacheException e) {
msg.setFailed(e.getRc(), e.getMessage());
} catch (RuntimeException e) {
LOGGER.error(e.toString(), e);
msg.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Pnfs rename failed");
}
}
Aggregations