Skip to content

Commit 06d4422

Browse files
committed
U unmount volume before mounting (to prevent failures)
1 parent be59501 commit 06d4422

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/main/java/io/github/fvarrui/javapackager/packagers/GenerateDmg.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package io.github.fvarrui.javapackager.packagers;
22

33
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
4+
import static io.github.fvarrui.javapackager.utils.CommandUtils.execute;
45

56
import java.io.File;
67
import java.util.Arrays;
78

89
import org.apache.commons.lang3.StringUtils;
910

1011
import io.github.fvarrui.javapackager.model.MacConfig;
11-
import io.github.fvarrui.javapackager.utils.CommandUtils;
1212
import io.github.fvarrui.javapackager.utils.FileUtils;
1313
import io.github.fvarrui.javapackager.utils.Logger;
1414
import io.github.fvarrui.javapackager.utils.ThreadUtils;
@@ -81,11 +81,14 @@ public File apply(Packager packager) throws Exception {
8181

8282
// creates image
8383
Logger.info("Creating image: " + tempDmgFile.getAbsolutePath());
84-
CommandUtils.execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", volumeName, "-ov", "-fs", "HFS+", "-format", "UDRW", tempDmgFile);
84+
execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", volumeName, "-ov", "-fs", "HFS+", "-format", "UDRW", tempDmgFile);
85+
86+
Logger.info("Unmounting disk image (if mounted)...");
87+
execute("hdiutil", "detach", volumeName);
8588

8689
// mounts image
8790
Logger.info("Mounting image: " + tempDmgFile.getAbsolutePath());
88-
String result = CommandUtils.execute("hdiutil", "attach", "-readwrite", "-noverify", "-noautoopen", tempDmgFile);
91+
String result = execute("hdiutil", "attach", "-readwrite", "-noverify", "-noautoopen", tempDmgFile);
8992
String deviceName = Arrays.asList(result.split("\n"))
9093
.stream()
9194
.filter(s -> s.contains(mountFolder.getAbsolutePath()))
@@ -106,26 +109,26 @@ public File apply(Packager packager) throws Exception {
106109

107110
// runs applescript
108111
Logger.info("Running applescript");
109-
CommandUtils.execute("/usr/bin/osascript", applescriptFile, volumeName);
112+
execute("/usr/bin/osascript", applescriptFile, volumeName);
110113

111114
// makes sure it's not world writeable and user readable
112115
Logger.info("Fixing permissions...");
113-
CommandUtils.execute("chmod", "-Rf", "u+r,go-w", mountFolder);
116+
execute("chmod", "-Rf", "u+r,go-w", mountFolder);
114117

115118
// makes the top window open itself on mount:
116119
Logger.info("Blessing ...");
117-
CommandUtils.execute("bless", "--folder", mountFolder, "--openfolder", mountFolder);
120+
execute("bless", "--folder", mountFolder, "--openfolder", mountFolder);
118121

119122
// tells the volume that it has a special file attribute
120-
CommandUtils.execute("SetFile", "-a", "C", mountFolder);
123+
execute("SetFile", "-a", "C", mountFolder);
121124

122125
// unmounts
123126
Logger.info("Unmounting disk image...");
124-
CommandUtils.execute("hdiutil", "detach", deviceName);
127+
execute("hdiutil", "detach", volumeName);
125128

126129
// compress image
127130
Logger.info("Compressing disk image...");
128-
CommandUtils.execute("hdiutil", "convert", tempDmgFile, "-format", "UDZO", "-imagekey", "zlib-level=9", "-o", dmgFile);
131+
execute("hdiutil", "convert", tempDmgFile, "-format", "UDZO", "-imagekey", "zlib-level=9", "-o", dmgFile);
129132
tempDmgFile.delete();
130133

131134
// checks if dmg file was created

0 commit comments

Comments
 (0)