public static void ensureMarkFileLink(final File serviceDir, final File actualFile, final String linkFilename)
    {
        final String serviceDirPath;
        final String markFileParentPath;

        try
        {
            serviceDirPath = serviceDir.getCanonicalPath();
        }
        catch (final IOException ex)
        {
            throw new IllegalArgumentException("failed to resolve canonical path for archiveDir=" + serviceDir);
        }

        try
        {
            markFileParentPath = actualFile.getParentFile().getCanonicalPath();
        }
        catch (final IOException ex)
        {
            throw new IllegalArgumentException(
                "failed to resolve canonical path for markFile parent dir of " + actualFile);
        }

        final Path linkFile = new File(serviceDirPath, linkFilename).toPath();
        if (serviceDirPath.equals(markFileParentPath))
        {
            try
            {
                Files.deleteIfExists(linkFile);
            }
            catch (final IOException ex)
            {
                throw new RuntimeException("failed to remove old link file", ex);
            }
        }
        else
        {
            try
            {
                Files.write(
                    linkFile,
                    markFileParentPath.getBytes(US_ASCII),
                    StandardOpenOption.CREATE,
                    StandardOpenOption.WRITE,
                    StandardOpenOption.TRUNCATE_EXISTING);
            }
            catch (final IOException ex)
            {
                throw new RuntimeException("failed to create link for mark file directory", ex);
            }
        }
    }
@Test
    void shouldRemoveLinkFileIfMarkFileIsInServiceDirectory() throws IOException
    {
        final String linkFilename = "markfile.lnk";
        final File markFileLocation = new File(serviceDirectory, "markfile.dat");
        final File linkFileLocation = new File(serviceDirectory, linkFilename);

        assertTrue(linkFileLocation.createNewFile());
        assertTrue(linkFileLocation.exists());

        MarkFile.ensureMarkFileLink(serviceDirectory, markFileLocation, linkFilename);
        assertFalse(linkFileLocation.exists());
    }