Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong assumption on creating tiffwriter.conf #4311

Open
henning-gerhardt opened this issue Mar 29, 2021 · 3 comments
Open

Wrong assumption on creating tiffwriter.conf #4311

henning-gerhardt opened this issue Mar 29, 2021 · 3 comments
Labels

Comments

@henning-gerhardt
Copy link
Collaborator

The creation of the tiffwriter.conf file is done in the assumption that the images directory of a process is existing in any case. If this is not the case the following error get logged

[ERROR] 2021-03-26 10:59:20,912 [http-nio-127.0.0.1-8080-exec-6] org.kitodo.production.helper.WebDav - errorDownloading
java.nio.file.NoSuchFileException: /home/goobi/work/daten/397/images/tiffwriter.conf
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86) ~[?:1.8.0_275]
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[?:1.8.0_275]
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[?:1.8.0_275]
        at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214) ~[?:1.8.0_275]
        at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434) ~[?:1.8.0_275]
        at java.nio.file.Files.newOutputStream(Files.java:216) ~[?:1.8.0_275]
        at org.kitodo.filemanagement.FileManagement.write(FileManagement.java:81) ~[kitodo-file-management-3.2.1-SNAPSHOT.jar:?]
        at org.kitodo.production.services.file.FileService.write(FileService.java:312) ~[classes/:3.2.1-SNAPSHOT]
        at org.kitodo.production.helper.WebDav.saveTiffHeader(WebDav.java:251) [classes/:3.2.1-SNAPSHOT]
        at org.kitodo.production.helper.WebDav.downloadToHome(WebDav.java:160) [classes/:3.2.1-SNAPSHOT]
        at org.kitodo.production.services.data.ProcessService.downloadToHome(ProcessService.java:2402) [classes/:3.2.1-SNAPSHOT]
        at org.kitodo.production.forms.ProcessListBaseView.downloadToHome(ProcessListBaseView.java:349) [classes/:3.2.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_275]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_275]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_275]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_275]
...

and the user get an error message displayed that the linking of the process into his user directory was failing.

In the method saveTiffHeader in the WebDav class (see https://github.com/kitodo/kitodo-production/blob/master/Kitodo/src/main/java/org/kitodo/production/helper/WebDav.java#L241-L257) is the wrong assumption or the missing check that the images directory exists or not.

One approach could be that on missing of the images directory this directory is created. This could be done by maybe the following code:

    private void saveTiffHeader(Process inProcess) {
        try {
            String imagesDirectory = fileService.getImagesDirectory(inProcess).getPath();
            String kitodoDataDirectory = ConfigCore.getKitodoDataDirectory();
            File kitodoImagesDirectory = Paths.get(kitodoDataDirectory, imagesDirectory).toFile();
            if (! kitodoImagesDirectory.exists()) {
                fileService.createDirectory(new File(kitodoDataDirectory).toURI(), imagesDirectory);
            }
            File tiffWriterFile = Paths.get(kitodoImagesDirectory.getAbsolutePath(), "tiffwriter.conf").toFile();
            if (tiffWriterFile.exists()) {
                return;
            }
            TiffHeader tif = new TiffHeader(inProcess);
            try (BufferedWriter outfile = new BufferedWriter(
                    new OutputStreamWriter(fileService.write(tiffWriterFile.toURI()), StandardCharsets.UTF_8))) {
                outfile.write(tif.getTiffAlles());
            }
        } catch (IOException | RuntimeException e) {
            Helper.setErrorMessage("errorDownloading", new Object[] {"Home" }, logger, e);
        }
    }

I'm not so familiar with the file management module nor the command module, so I did the changes in a quick a dirty way: check for the existence of the images directory and create it in the other case. I did even remove some of URI <-> File <-> String calls, which may must be stay but I did not see the reason for it.

Maybe some one other has more knowledge and can convert this fast, dirty hack into some beautiful flower of code.

@matthias-ronge
Copy link
Collaborator

matthias-ronge commented Mar 29, 2021

That would be a theme related to #3659, another “secret” use of the images folder. By the way: Is this Tiffwriter configuration used by anyone? Was there a reason not to include this in the application, if needed, or to remove it if not?

I can't say that either. But I would estimate an empty directory to be roughly 16 bytes. If you have eight empty directories per parent process, for 200,000 processes, that would be roughly 2.4 MB. Yes, it's unnecessary, but it's not the biggest problem.

@henning-gerhardt
Copy link
Collaborator Author

By the way: Is this Tiffwriter configuration used by anyone? Was there a reason not to include this in the application, if needed, or to remove it if not?

See https://github.com/kitodo/kitodo-production/wiki/Verwendung-der-tiffwriterconf-Datei ... there is at least one institute which is using this. Personally I was for removing this but there was an other decision.

But I would estimate an empty directory to be roughly 16 bytes.

This is depending on the used file system and can not counted in this way.

If you have eight empty directories per parent process, for 200,000 processes, that would be roughly 2.4 MB. Yes, it's unnecessary, but it's not the biggest problem.

Did you mixed up this comment to with an other issue? This issue is independent from other ones!

@matthias-ronge
Copy link
Collaborator

matthias-ronge commented Mar 29, 2021

Did you mixed up this comment to with an other issue?

Yes, this was in the wrong issue.

@solth solth removed the 3.x label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants