Merge pull request #1191 from scm-manager/bugfix/close_file_list_in_migration

Close file lists
This commit is contained in:
eheimbuch
2020-06-17 08:42:45 +02:00
committed by GitHub
5 changed files with 23 additions and 13 deletions

View File

@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixes configuration of jetty listener address with system property `jetty.host` ([#1173](https://github.com/scm-manager/scm-manager/pull/1173), [#1174](https://github.com/scm-manager/scm-manager/pull/1174))
- Fixes loading plugin bundles with context path `/` ([#1182](https://github.com/scm-manager/scm-manager/pull/1182/files), [#1181](https://github.com/scm-manager/scm-manager/issues/1181))
- Sets the new plugin center URL once ([#1184](https://github.com/scm-manager/scm-manager/pull/1184))
- Close file lists in migration ([#1191](https://github.com/scm-manager/scm-manager/pull/1191))
- Use command in javahg.py from registrar (Upgrade to newer javahg version) ([#1192](https://github.com/scm-manager/scm-manager/pull/1192))
## [2.0.0] - 2020-06-04

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.update.repository;
import sonia.scm.SCMContextProvider;
@@ -31,6 +31,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.stream.Stream;
abstract class BaseMigrationStrategy implements MigrationStrategy.Instance {
@@ -50,9 +51,9 @@ abstract class BaseMigrationStrategy implements MigrationStrategy.Instance {
return contextProvider.getBaseDirectory().toPath().resolve("repositories").resolve(type);
}
Stream<Path> listSourceDirectory(Path sourceDirectory) {
try {
return Files.list(sourceDirectory);
void listSourceDirectory(Path sourceDirectory, Consumer<Stream<Path>> pathConsumer) {
try (Stream<Path> paths = Files.list(sourceDirectory)) {
pathConsumer.accept(paths);
} catch (IOException e) {
throw new UpdateException("could not read original directory", e);
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.update.repository;
import org.slf4j.Logger;
@@ -62,15 +62,17 @@ class CopyMigrationStrategy extends BaseMigrationStrategy {
private void copyData(Path sourceDirectory, Path targetDirectory) {
createDataDirectory(targetDirectory);
listSourceDirectory(sourceDirectory).forEach(
listSourceDirectory(sourceDirectory, paths -> paths.forEach(
sourceFile -> {
Path targetFile = targetDirectory.resolve(sourceFile.getFileName());
if (Files.isDirectory(sourceFile)) {
LOG.trace("traversing down into sub directory {}", sourceFile);
copyData(sourceFile, targetFile);
} else {
LOG.trace("copying file {} to {}", sourceFile, targetFile);
copyFile(sourceFile, targetFile);
}
}
);
));
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.update.repository;
import org.slf4j.Logger;
@@ -67,20 +67,23 @@ class InlineMigrationStrategy extends BaseMigrationStrategy {
private void moveData(Path sourceDirectory, Path targetDirectory, boolean deleteDirectory) {
createDataDirectory(targetDirectory);
listSourceDirectory(sourceDirectory)
listSourceDirectory(sourceDirectory, paths -> paths
.filter(sourceFile -> !targetDirectory.equals(sourceFile))
.forEach(
sourceFile -> {
Path targetFile = targetDirectory.resolve(sourceFile.getFileName());
if (Files.isDirectory(sourceFile)) {
LOG.trace("traversing down into sub directory {}", sourceFile);
moveData(sourceFile, targetFile, true);
} else {
LOG.trace("moving file {} to {}", sourceFile, targetFile);
moveFile(sourceFile, targetFile);
}
}
);
));
if (deleteDirectory) {
try {
LOG.trace("deleting source directory {}", sourceDirectory);
Files.delete(sourceDirectory);
} catch (IOException e) {
LOG.warn("could not delete source repository directory {}", sourceDirectory);

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.update.repository;
import org.slf4j.Logger;
@@ -83,17 +83,20 @@ class MoveMigrationStrategy extends BaseMigrationStrategy {
private void moveData(Path sourceDirectory, Path targetDirectory) {
createDataDirectory(targetDirectory);
listSourceDirectory(sourceDirectory).forEach(
listSourceDirectory(sourceDirectory, paths -> paths.forEach(
sourceFile -> {
Path targetFile = targetDirectory.resolve(sourceFile.getFileName());
if (Files.isDirectory(sourceFile)) {
LOG.trace("traversing down into sub directory {}", sourceFile);
moveData(sourceFile, targetFile);
} else {
LOG.trace("moving file {} to {}", sourceFile, targetFile);
moveFile(sourceFile, targetFile);
}
}
);
));
try {
LOG.trace("deleting source directory {}", sourceDirectory);
Files.delete(sourceDirectory);
} catch (IOException e) {
LOG.warn("could not delete source repository directory {}", sourceDirectory);