CcmNG:
- More functions for the CcmFiles service - FileSystemThemeProvider for serving themes from the file system (using CcmFiles) git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5681 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
dbcdd0aaf2
commit
d7e64c20f4
|
|
@ -403,6 +403,12 @@ public class CcmFiles {
|
|||
getFileSystemAdapter().copy(sourcePath, targetPath, recursive);
|
||||
}
|
||||
|
||||
public void moveFile(final String sourcePath,
|
||||
final String targetPath) throws FileAccessException {
|
||||
|
||||
getFileSystemAdapter().move(sourcePath, targetPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a file or directory. If the file is a directory the directory must
|
||||
* be empty.
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ public interface FileSystemAdapter {
|
|||
String targetPath,
|
||||
boolean recursive) throws FileAccessException;
|
||||
|
||||
void move(String sourcePath, String targetPath) throws FileAccessException;
|
||||
|
||||
/**
|
||||
* checks if the provided path points to a directory.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -319,7 +319,25 @@ public class NIOFileSystemAdapter implements FileSystemAdapter {
|
|||
throw new FileAccessException(sourcePath, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(final String sourcePath, final String targetPath)
|
||||
throws FileAccessException {
|
||||
|
||||
final Path nioSourcePath = Paths.get(sourcePath);
|
||||
final Path nioTargetPath = Paths.get(targetPath);
|
||||
|
||||
try {
|
||||
Files.move(nioSourcePath,
|
||||
nioTargetPath,
|
||||
StandardCopyOption.ATOMIC_MOVE,
|
||||
StandardCopyOption.COPY_ATTRIBUTES,
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
LinkOption.NOFOLLOW_LINKS);
|
||||
} catch(IOException ex) {
|
||||
throw new FileAccessException(targetPath, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import java.io.OutputStream;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -233,13 +235,21 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
ThemeVersion.DRAFT);
|
||||
final String liveThemePath = createThemePath(theme,
|
||||
ThemeVersion.LIVE);
|
||||
final String liveThemePathTmp = String.format("%_tmp", liveThemePath);
|
||||
|
||||
try {
|
||||
ccmFiles.copyFile(draftThemePath, liveThemePath, true);
|
||||
} catch (FileAccessException ex) {
|
||||
throw new UnexpectedErrorException();
|
||||
ccmFiles.copyFile(draftThemePath, liveThemePathTmp, true);
|
||||
if (ccmFiles.existsFile(liveThemePath)) {
|
||||
ccmFiles.deleteFile(liveThemePath, true);
|
||||
}
|
||||
|
||||
ccmFiles.moveFile(liveThemePathTmp, liveThemePath);
|
||||
} catch (DirectoryNotEmptyException
|
||||
| FileAccessException
|
||||
| FileDoesNotExistException
|
||||
| InsufficientPermissionsException ex) {
|
||||
throw new UnexpectedErrorException();
|
||||
}
|
||||
}
|
||||
|
||||
private String createThemePath(final String theme,
|
||||
|
|
|
|||
|
|
@ -265,6 +265,28 @@ public class XAFileSystemAdapter implements FileSystemAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(final String sourcePath,
|
||||
final String targetPath)
|
||||
throws FileAccessException {
|
||||
|
||||
final XADiskConnection connection = connect();
|
||||
final File sourceFile = new File(sourcePath);
|
||||
final File targetFile = new File(targetPath);
|
||||
|
||||
try {
|
||||
connection.moveFile(sourceFile, targetFile);
|
||||
} catch(org.xadisk.filesystem.exceptions.FileAlreadyExistsException
|
||||
| FileNotExistsException
|
||||
| FileUnderUseException
|
||||
| InsufficientPermissionOnFileException
|
||||
| InterruptedException
|
||||
| LockingFailedException
|
||||
| NoTransactionAssociatedException ex) {
|
||||
throw new FileAccessException(targetPath, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public boolean isDirectory(final String path)
|
||||
|
|
|
|||
Loading…
Reference in New Issue