mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-22 15:32:16 +01:00
Merged in bugfix/keep_file_attributes (pull request #414)
Keep file attributes on modification
This commit is contained in:
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Fixed
|
||||
- Modification for mercurial repositories with enabled XSRF protection
|
||||
- Does not throw NullPointerException when merge fails without normal merge conflicts
|
||||
- Keep file attributes on modification
|
||||
|
||||
### Removed
|
||||
- Enunciate rest documentation
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
@@ -22,6 +24,8 @@ import static sonia.scm.NotFoundException.notFound;
|
||||
*/
|
||||
public interface ModifyWorkerHelper extends ModifyCommand.Worker {
|
||||
|
||||
Logger LOG = LoggerFactory.getLogger(ModifyWorkerHelper.class);
|
||||
|
||||
@Override
|
||||
default void delete(String toBeDeleted) throws IOException {
|
||||
Path fileToBeDeleted = new File(getWorkDir(), toBeDeleted).toPath();
|
||||
@@ -57,7 +61,11 @@ public interface ModifyWorkerHelper extends ModifyCommand.Worker {
|
||||
if (!targetFile.toFile().exists()) {
|
||||
throw notFound(createFileContext(path));
|
||||
}
|
||||
boolean executable = Files.isExecutable(targetFile);
|
||||
Files.move(file.toPath(), targetFile, REPLACE_EXISTING);
|
||||
if (targetFile.toFile().setExecutable(executable)) {
|
||||
LOG.warn("could not set executable flag for file {}", targetFile);
|
||||
}
|
||||
addFileToScm(path, targetFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class ModifyWorkerHelperTest {
|
||||
|
||||
@Test
|
||||
void shouldKeepExecutableFlag(@TempDirectory.TempDir Path temp) throws IOException {
|
||||
|
||||
File target = createFile(temp, "executable.sh");
|
||||
File newFile = createFile(temp, "other");
|
||||
|
||||
target.setExecutable(true);
|
||||
|
||||
ModifyWorkerHelper helper = new MinimalModifyWorkerHelper(temp);
|
||||
|
||||
helper.modify("executable.sh", newFile);
|
||||
|
||||
assertThat(target.canExecute()).isTrue();
|
||||
}
|
||||
|
||||
private File createFile(Path temp, String fileName) throws IOException {
|
||||
File file = new File(temp.toFile(), fileName);
|
||||
FileWriter source = new FileWriter(file);
|
||||
source.write("something");
|
||||
source.close();
|
||||
return file;
|
||||
}
|
||||
|
||||
private static class MinimalModifyWorkerHelper implements ModifyWorkerHelper {
|
||||
|
||||
private final Path temp;
|
||||
|
||||
public MinimalModifyWorkerHelper(Path temp) {
|
||||
this.temp = temp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doScmDelete(String toBeDeleted) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFileToScm(String name, Path file) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorkDir() {
|
||||
return temp.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getRepository() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBranch() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user