@Override
    public Path move(final Path source, final Path target, final TransferStatus status, final Callback delete, final ConnectionCallback prompt) throws BackgroundException {
        final SMBSession.DiskShareWrapper share = session.openShare(source);
        try {
            try (DiskEntry file = share.get().open(new SMBPathContainerService(session).getKey(source),
                    Collections.singleton(AccessMask.DELETE),
                    Collections.singleton(FileAttributes.FILE_ATTRIBUTE_NORMAL),
                    Collections.singleton(SMB2ShareAccess.FILE_SHARE_READ),
                    SMB2CreateDisposition.FILE_OPEN,
                    Collections.singleton(source.isDirectory() ? SMB2CreateOptions.FILE_DIRECTORY_FILE : SMB2CreateOptions.FILE_NON_DIRECTORY_FILE))) {
                file.rename(new SmbPath(share.get().getSmbPath(), new SMBPathContainerService(session).getKey(target)).getPath(), status.isExists());
            }
        }
        catch(SMBRuntimeException e) {
            throw new SMBExceptionMappingService().map("Cannot rename {0}", e, source);
        }
        finally {
            session.releaseShare(share);
        }
        // Copy original file attributes
        return target.withAttributes(source.attributes());
    }
@Test
    public void testRename() throws Exception {
        final Path home = new DefaultHomeFinderService(session).find();
        final Path folder = new SMBDirectoryFeature(session).mkdir(
                new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
        final Path file = new SMBTouchFeature(session).touch(
                new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());

        // rename file
        final Path fileRenamed = new SMBMoveFeature(session).move(file, new Path(folder,
                        new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(),
                new Delete.DisabledCallback(), new DisabledConnectionCallback());

        assertFalse(new SMBFindFeature(session).find(file));
        assertTrue(new SMBFindFeature(session).find(fileRenamed));
        assertEquals(file.attributes(), fileRenamed.attributes());

        // rename folder
        final Path folderRenamed = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
        new SMBMoveFeature(session).move(folder, folderRenamed, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());

        assertFalse(new SMBFindFeature(session).find(folder));
        assertTrue(new SMBFindFeature(session).find(folderRenamed));
        final Path fileRenamedInRenamedFolder = new Path(folderRenamed, fileRenamed.getName(), EnumSet.of(Path.Type.file));
        assertTrue(new SMBFindFeature(session).find(fileRenamedInRenamedFolder));
        new SMBDeleteFeature(session).delete(Collections.singletonList(folderRenamed), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }