Skip to content

Commit

Permalink
FURNACE-93: Support addon deployment as symlinks
Browse files Browse the repository at this point in the history
In order to avoid java.nio.file.FileSystemException: A required privilege is not held by the client,
follow this instruction: http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files
  • Loading branch information
gastaldi committed Nov 4, 2015
1 parent 0e6ab50 commit 578b4f3
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
*/
public final class AddonRepositoryImpl implements MutableAddonRepository
{
/**
* Setting this system property to <code>true</code> allows Furnace to deploy addons as symlinks
*/
private static final String DEPLOY_AS_SYMLINK_SYSTEM_PROPERTY = "furnace.addon.deploy_as_symlink";

private static final Logger logger = Logger.getLogger(AddonRepositoryImpl.class.getName());

Expand Down Expand Up @@ -139,13 +143,31 @@ public Boolean call() throws Exception
+ resource.getParentFile().getParentFile().getName();
child = OperatingSystemUtils.getSafeFilename(child);
File target = new File(addonSlotDir, child);
logger.fine("Copying " + resource + " to " + target);
Files.copyDirectory(resource, target);
if (Boolean.getBoolean(DEPLOY_AS_SYMLINK_SYSTEM_PROPERTY))
{
logger.fine("Creating symlink from " + resource + " to " + target);
java.nio.file.Files.createSymbolicLink(target.toPath(), resource.toPath());
}
else
{
logger.fine("Copying " + resource + " to " + target);
Files.copyDirectory(resource, target);
}
}
else
{
logger.fine("Copying " + resource + " to " + addonSlotDir);
Files.copyFileToDirectory(resource, addonSlotDir);
if (Boolean.getBoolean(DEPLOY_AS_SYMLINK_SYSTEM_PROPERTY))
{
logger.fine("Creating symlink from " + resource + " to "
+ addonSlotDir.toPath().resolve(resource.getName()));
java.nio.file.Files.createSymbolicLink(addonSlotDir.toPath().resolve(resource.getName()),
resource.toPath());
}
else
{
logger.fine("Copying " + resource + " to " + addonSlotDir);
Files.copyFileToDirectory(resource, addonSlotDir);
}
}
}
}
Expand Down Expand Up @@ -180,21 +202,15 @@ public Boolean call() throws Exception
}
}

FileOutputStream fos = null;
try
try (FileOutputStream fos = new FileOutputStream(descriptor))
{
fos = new FileOutputStream(descriptor);
Streams.write(XMLParser.toXMLInputStream(addonXml), fos);
}
finally
{
Streams.closeQuietly(fos);
}
return true;
}
catch (IOException io)
{
io.printStackTrace();
logger.log(Level.SEVERE, "Error while deploying addon " + addon, io);
return false;
}
}
Expand Down

0 comments on commit 578b4f3

Please sign in to comment.