Migrating a java application from a case-insensitive file system to a case-sensitive file

We have been using our Java code on Windows servers for many years. We want to run the same code in some FreeBSD blocks, but our code grew up in an environment where the file / path name is case insensitive for so long that most of the code will break.

What I want to do is some kind of trick in which we subclass File or FileSystem or some similar trick, and this makes all our file names work in lower case (all the time).

It seems quite possible (for example, to extend a file with a new OurFile class, which forces everything in lowercase). Then we run a script that turns all files / folders into lowercase OS and bam, reset errors.

It seems that a similar hack with the new FileSystem implementation will also give a good result.

Then I thought - surely someone in front of me ran into this problem and licked it well.

So what is wisdom? Is there a simple / standard way to solve this case sensitivity problem? (i.e. someone wrote LowerCaseFileSystemForPortingWindowsToUnix extends the file system and tested it, etc.?)

+4
source share
2 answers

Have you considered fixing a code? From your description, you seem to have a lot of links to a file / resource that are case-insensitive (so to speak, incorrect) names in the code ... This can be done either by adapting the file names to the way they are mentioned in the code ( only if there are some consequences in the code, fg all file names are lowercase) or adapt the constants in the code to match the file names.

Any wrappers for the java.io classes will require you to list all the files / directories anywhere in the path and try to find a name that matches the path. However, in the U ** x system, you can have both the resources directories and resources , etc., And which one would you choose for the path "RESOURCES / IMAGES / MYIMAGE.PNG"? In addition, you will have performance issues for I / O operations.

I once “fixed” such a project, but soon it was very small, but it was very unpleasant. For my luck, some operations can be written in a script, for example, changing all the constants in one file on the lower and lower cases of all image file names, etc.

0
source

If your file access methods go through a small number of classes (e.g. new File(String filename) ), you can use AspectJ to bind in some code that changes the case of the file name as it goes through.

Sort of:

 @Around(value = "newFile(context)", argNames = "point") public Object requiresNew(ProceedingJoinPoint point) throws Throwable { String filename = (String) point.getArgs()[0]; return point.proceed(new String[] { filename.toLowerCase() }); } 

This will probably be much less intrusive for your code base than the File extension, plus it will give you an exit strategy:

  • log.warn() all missing file names that are not fully lowercase.
  • Correct warnings as they arise.
  • Remove the aspect after placing it in
-2
source

Source: https://habr.com/ru/post/1397711/


All Articles