@fredlackey/devutils 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,11 +9,53 @@
9
9
  const shell = require('../common/shell');
10
10
 
11
11
  /**
12
- * Checks if snapd is installed and running
13
- * @returns {boolean}
12
+ * Checks if snapd is installed and the daemon is accessible.
13
+ *
14
+ * This function verifies both that the snap command exists AND that
15
+ * the snapd daemon is running and can be communicated with. This is
16
+ * important because in some environments (like Docker containers),
17
+ * the snap command may be installed but the daemon cannot run.
18
+ *
19
+ * @returns {boolean} True if snap command exists AND daemon is accessible
14
20
  */
15
21
  function isInstalled() {
16
- return shell.commandExists('snap');
22
+ // First check if snap command exists
23
+ if (!shell.commandExists('snap')) {
24
+ return false;
25
+ }
26
+
27
+ // Check if snapd daemon is accessible by checking snap version output
28
+ // Using syncExec for immediate result without spawning async process
29
+ const { execSync } = require('child_process');
30
+ try {
31
+ // Try to get snap version info with a short timeout
32
+ // In Docker without systemd, this may timeout or return "snapd unavailable"
33
+ const output = execSync('snap version 2>/dev/null', {
34
+ stdio: 'pipe',
35
+ timeout: 1000,
36
+ encoding: 'utf8'
37
+ });
38
+
39
+ // Check if snapd is listed as unavailable
40
+ // When snapd daemon is not running, snap version shows:
41
+ // snap 2.73+ubuntu22.04
42
+ // snapd unavailable
43
+ // series -
44
+ if (output.includes('snapd unavailable') || output.includes('snapd unavailable')) {
45
+ return false;
46
+ }
47
+
48
+ // Also check for empty or malformed output
49
+ if (!output || output.trim().length === 0) {
50
+ return false;
51
+ }
52
+
53
+ return true;
54
+ } catch (err) {
55
+ // If snap version command fails (timeout, error), daemon is not accessible
56
+ // This handles the Docker case where snap command hangs trying to reach daemon
57
+ return false;
58
+ }
17
59
  }
18
60
 
19
61
  /**