Working with unix symlink files on a Windows file system

I am currently working on a Java project that should allow the user to export projects bundled with Windows software (.exe) or OS X app (.app) to distribute data to other workstations. Windows and OS X software is stored as a compressed zip file and uncompressed if the project is exported. My problem is that unpacking an OS X application on Windows breaks symbolic links inside related frameworks. This, in turn, violates the application signature and causes problems when launching the application in OS X.

I use Apache Commons compression libraries to unpack packages, which allows me to detect symbolic links and their purpose. With OS X, I can recreate a symbolic link with methods from java.nio.file.Files, but with Windows it will require administrator rights, which I hesitate to add as a prerequisite for using the software (even if it’s on, I’m not sure that it works - did not try).

I have little understanding of the reason why the links are broken, but if I understood correctly, the Windows file system does not include support for the Unix symbolic link file type, and therefore the link is unpacked as a regular file and will no longer be recognized as a symbolic link when opened on OS X.

So my question is, can I just somehow smash a copy of a symbolic link file in a Windows file system, preserving specific Unix bits or storing this information is completely impossible? Or do I just need to change the export method to add project files to an existing zip file, in which case the symbolic link information will probably be saved until the zip is extracted on the target machine?

The current code loop above each is ZipArchiveEntry ZipFileas follows:

byte data[] = new byte[BUFFER];

Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();

while (entries.hasMoreElements()) {
    ZipArchiveEntry zipEntry = entries.nextElement();
    String destFilename = copyFolder + zipEntry.getName();
    File destFile = new File(destFilename);

    if (zipEntry.isUnixSymlink()) {             
        File target = new File(zipFile.getUnixSymlink(zipEntry));              
        try {   
            // Try to create symbolic link - currently only works with OS X
            Files.createSymbolicLink(destFile.toPath(), target.toPath());
            continue;
        } catch (Exception e) {
            System.out.println("Failed to create symbolic link: " + 
                destFile.getAbsolutePath() + " -> " + 
                target.getAbsolutePath());
        }
    }

    // If file
    int count;
    FileOutputStream fos = new FileOutputStream(destFile);

    try (BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER)) {
        InputStream is = zipFile.getInputStream(zipEntry);
        while ( (count = is.read(data, 0, BUFFER)) != -1) {
            dest.write(data, 0, count);
        }
    }
}
+4
source share
3 answers

Windows UNIX, , (, ), 100% . : https://msdn.microsoft.com/en-us/library/windows/desktop/aa365680(v=vs.85).aspx - Unix, Windows NTFS . JAVA , API, ", ". ​​ JAVA. , .

, . ? , - " ", ? ? .

+3

Windows "" ( , Java) , Java-. , Runtime.exec mklink. mklink () , - , Windows. , JNA Kernel32.dll Kernel32.dll WinBase.h CreateSymbolicLink(LPTSTR,LPTSTR,DWORD).

+3

, Windows, .

Symlinks Hardlinks Windows , :

  • Windows .
  • NTFS, (FAT, exFAT, UDF) .
  • (Zipper, , ), Microsoft (, " ", Windows "Time Machine" Windows / ) , , / ).
  • , , Windows ( Windows 7 () , , Windows XP )

, ( ), , , , , UNIX ZIP .

+1
source

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


All Articles