4747import edu .kit .datamanager .util .PatchUtil ;
4848import java .io .InputStream ;
4949import java .net .URI ;
50- import java .net .URISyntaxException ;
5150import java .net .URL ;
52- import java .nio .file .Files ;
53- import java .nio .file .Path ;
54- import java .nio .file .Paths ;
5551import java .time .Instant ;
5652import java .util .ArrayList ;
5753import java .util .Collection ;
6460import java .util .Optional ;
6561import java .util .Set ;
6662import jakarta .servlet .http .HttpServletResponse ;
63+ import java .io .File ;
64+ import java .util .concurrent .ExecutorService ;
65+ import java .util .concurrent .Executors ;
66+ import java .util .concurrent .Future ;
67+ import java .util .concurrent .TimeUnit ;
68+ import java .util .concurrent .TimeoutException ;
6769import org .slf4j .Logger ;
6870import org .slf4j .LoggerFactory ;
6971import org .springframework .beans .factory .annotation .Autowired ;
@@ -545,7 +547,29 @@ public Health health() {
545547 LOGGER .trace ("Obtaining health information." );
546548 boolean repositoryPathAvailable = true ;
547549 URL basePath = applicationProperties .getBasepath ();
550+ ExecutorService executor = Executors .newSingleThreadExecutor ();
551+
552+ Future <Boolean > future = executor .submit (() -> {
553+ File mount = new File (basePath .toURI ());
554+ return mount .exists () && mount .isDirectory () && mount .canRead () && mount .list () != null ;
555+ });
556+
548557 try {
558+ LOGGER .trace ("Checking repository path at {}." , basePath );
559+ Boolean accessible = future .get (5 , TimeUnit .SECONDS );
560+ LOGGER .trace ("Repository path is " + (accessible ? "accessible" : "not accessible" ));
561+ repositoryPathAvailable = accessible ;
562+ } catch (TimeoutException e ) {
563+ LOGGER .error ("Timeout while checking repository path." );
564+ repositoryPathAvailable = false ;
565+ } catch (Exception e ) {
566+ LOGGER .error ("Error while checking repository path." , e );
567+ repositoryPathAvailable = false ;
568+ } finally {
569+ executor .shutdownNow ();
570+ }
571+
572+ /*try {
549573 Path basePathAsPath = Paths.get(basePath.toURI());
550574 Path probe = Paths.get(basePathAsPath.toString(), "probe.txt");
551575 try {
@@ -563,7 +587,7 @@ public Health health() {
563587 } catch (URISyntaxException ex) {
564588 LOGGER.error("Invalid base path uri of " + basePath + ".", ex);
565589 repositoryPathAvailable = false;
566- }
590+ }*/
567591 if (repositoryPathAvailable ) {
568592 return Health .up ().withDetail ("ContentInformation" , dao .count ()).build ();
569593 } else {
0 commit comments