Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Set hidden file attribute on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
britter committed Mar 21, 2020
1 parent 0be84b0 commit f6e2c95
Showing 1 changed file with 19 additions and 2 deletions.
@@ -1,12 +1,14 @@
package com.github.britter.beanvalidators.file;

import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.DosFileAttributeView;

abstract class BaseFileTest {

Expand All @@ -23,7 +25,11 @@ File file() {

File file(String name) {
try {
return Files.createFile(tmpDir.resolve(name)).toFile();
File file = Files.createFile(tmpDir.resolve(name)).toFile();
if (name.startsWith(".")) {
makeHidden(file);
}
return file;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -35,9 +41,20 @@ File dir() {

File dir(String name) {
try {
return Files.createDirectory(tmpDir.resolve(name)).toFile();
File dir = Files.createDirectory(tmpDir.resolve(name)).toFile();
if (name.startsWith(".")) {
makeHidden(dir);
}
return dir;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private void makeHidden(File file) throws IOException {
if (SystemUtils.IS_OS_WINDOWS) {
DosFileAttributeView attributes = Files.getFileAttributeView(file.toPath(), DosFileAttributeView.class);
attributes.setHidden(true);
}
}
}

0 comments on commit f6e2c95

Please sign in to comment.