简体   繁体   English

将Java应用程序从不区分大小写的文件系统移动到区分大小写的文件系统

[英]Moving java app from a case insensitive file system to a case sensitive one

We have been running our Java code on windows servers for years. 多年来,我们一直在Windows服务器上运行Java代码。 We want to run the same code on some FreeBSD boxes but our code has grown up in an environment where file/path name are case insensitive for so long that a lot of the code will break. 我们想在某些FreeBSD机器上运行相同的代码,但是我们的代码在文件/路径名不区分大小写的环境中成长了很长时间,以至于很多代码都会中断。

What I want to do is some sort of trick where we subclass File or FileSystem or some similar trick and this forces all our file names to lower case (all the time). 我想要做的是某种技巧,其中我们将File或FileSystem子类化,或者类似的技巧,这会强制我们所有文件名始终使用小写。

It seems pretty possible (ie extend File with a new class OurFile that forces everything lower case). 似乎很有可能(即用新的类OurFile扩展File,强制所有小写)。 Then we would run a script that turns all files/folders on the OS lower case and bam, bugs squashed. 然后,我们将运行一个脚本,将操作系统上的所有文件/文件夹都转换为小写字母,并将bam和bug压缩掉。

It seems like some similar hacking with a new FileSystem implementation would also yield a good result. 似乎使用新的FileSystem实现进行一些类似的黑客攻击也会产生良好的结果。

I then thought -- surely someone before me has faced this issue and licked it good. 然后我想-肯定是我之前有人遇到过这个问题,并很好地解决了这个问题。

So, what is the wisdom out there? 那么,那里有什么智慧呢? Is there an easy/standard way to fix this sort of case sensitivity problem? 有没有简单/标准的方法来解决这种区分大小写的问题? (ie has someone written LowerCaseFileSystemForPortingWindowsToUnix extends FileSystem, and tested it etc.?) (即是否有人编写了LowerCaseFileSystemForPortingWindowsToUnix扩展了FileSystem,并对其进行了测试等?)

Have you considered fixing your code? 您是否考虑过修改代码? From your description, you seem to have a lot of file/resource references which 'case-insensitive' (so, simply speaking, incorrect) names in code... It can be done either by adapting file names to how they are referenced in code (only when there is some consequence in code, fg all file names are lower-case) or adapt the constants in code to match file names. 从您的描述中,您似乎有很多文件/资源​​引用,它们在代码中“不区分大小写”(因此,简单地说,是不正确的)名称...可以通过调整文件名以使其在代码中被引用来实现代码(仅在代码中有某些后果时,例如所有文件名均为小写)或使代码中的常量与文件名匹配。

Any wraps to java.io classes would require to list all files/directories anywhere in path and trying to find name that would match the path. 对java.io类的任何环绕都需要在路径中的任何位置列出所有文件/目录,并尝试查找与路径匹配的名称。 However, on U**x system you could have both resources and Resources directory etc., so which one would you take for path 'RESOURCES/IMAGES/MYIMAGE.PNG'? 但是,在U ** x系统上,您可能同时拥有resourcesResources目录等,那么对于路径“ RESOURCES / IMAGES / MYIMAGE.PNG”,您应该选择哪一个? Additionally, you would suffer from performance issues for I/O operations. 此外,您将遭受I / O操作的性能问题。

I've once 'fixed' such project, fortunatelly it was quite small, but it was very annoying. 我曾经“修复”这样的项目,所幸的是它很小,但是很烦人。 For my luck, some operations could be scripted, for example changing all constants in single file to lower-case and lower-casing all image filenames etc. 幸运的是,可以对某些操作进行脚本编写,例如将单个文件中的所有常量更改为小写,并将所有图像文件名都使用小写字母等。

If your file access methods go through a small number of classes (like new File(String filename) ) then you might be able to use AspectJ to weave in some code which modifies the case of the filename as it is passed through. 如果您的文件访问方法经过少量的类(例如new File(String filename) ),则您可以使用AspectJ编织一些代码,该代码修改文件名通过时的大小写。

Something like: 就像是:

@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 would probably be a lot less intrusive on your codebase than extending File , plus it would give you an exit strategy: 与扩展File ,这对代码库的干扰可能要小得多,而且它还会为您提供退出策略:

  1. log.warn() all filenames passed through which are not entirely lower case log.warn()传递的所有文件名都不是完全小写的
  2. Fix the warnings as they arise 修正出现的警告
  3. Remove the aspect once it's bedded in 嵌入外观后将其移除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM