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-94f89814c4df
Former-commit-id: 8da1e4c8c1
pull/2/head
parent
4b0e83dfca
commit
292f073f87
|
|
@ -403,6 +403,12 @@ public class CcmFiles {
|
||||||
getFileSystemAdapter().copy(sourcePath, targetPath, recursive);
|
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
|
* Delete a file or directory. If the file is a directory the directory must
|
||||||
* be empty.
|
* be empty.
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,8 @@ public interface FileSystemAdapter {
|
||||||
String targetPath,
|
String targetPath,
|
||||||
boolean recursive) throws FileAccessException;
|
boolean recursive) throws FileAccessException;
|
||||||
|
|
||||||
|
void move(String sourcePath, String targetPath) throws FileAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if the provided path points to a directory.
|
* checks if the provided path points to a directory.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -319,7 +319,25 @@ public class NIOFileSystemAdapter implements FileSystemAdapter {
|
||||||
throw new FileAccessException(sourcePath, ex);
|
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
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ import java.io.OutputStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -233,13 +235,21 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
ThemeVersion.DRAFT);
|
ThemeVersion.DRAFT);
|
||||||
final String liveThemePath = createThemePath(theme,
|
final String liveThemePath = createThemePath(theme,
|
||||||
ThemeVersion.LIVE);
|
ThemeVersion.LIVE);
|
||||||
|
final String liveThemePathTmp = String.format("%_tmp", liveThemePath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ccmFiles.copyFile(draftThemePath, liveThemePath, true);
|
ccmFiles.copyFile(draftThemePath, liveThemePathTmp, true);
|
||||||
} catch (FileAccessException ex) {
|
if (ccmFiles.existsFile(liveThemePath)) {
|
||||||
|
ccmFiles.deleteFile(liveThemePath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ccmFiles.moveFile(liveThemePathTmp, liveThemePath);
|
||||||
|
} catch (DirectoryNotEmptyException
|
||||||
|
| FileAccessException
|
||||||
|
| FileDoesNotExistException
|
||||||
|
| InsufficientPermissionsException ex) {
|
||||||
throw new UnexpectedErrorException();
|
throw new UnexpectedErrorException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createThemePath(final String theme,
|
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)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
@Override
|
@Override
|
||||||
public boolean isDirectory(final String path)
|
public boolean isDirectory(final String path)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue