Skip to content

Commit

Permalink
Auto-merge for PR #246 via VersionBot
Browse files Browse the repository at this point in the history
fix(darwin): Allow mountpoints containing space characters
  • Loading branch information
resin-io-modules-versionbot[bot] authored Jan 12, 2018
2 parents 5856fa0 + 0fe735c commit 750cc1c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v6.0.1 - 2018-01-12

* Fix(darwin): Allow mountpoints containing space characters #246 [Andrew Scheller]

## v6.0.0 - 2018-01-05

* Feat: Rewrite native bindings to use IOCTL #243 [Jonas Hermsmeier]
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"darwin": {
"content": "#!/bin/bash\n\nset -u\nset -e\n\nget_key() {\n\n # This expression is intentionally unquoted so that\n # multiple lines get joined as a single one.\n # See https://github.com/resin-io-modules/drivelist/pull/129\n echo $(grep \"$1\" | awk -F \" +\" '{ print $3 }')\n\n}\n\nget_until_paren() {\n awk 'match($0, \"\\\\(|$\"){ print substr($0, 0, RSTART - 1) }'\n}\n\nDISKS=\"$(diskutil list | grep '^\\/' | get_until_paren)\"\nmount_output=\"$(mount)\"\n\nfor disk in $DISKS; do\n\n # Ignore drives that were just unplugged\n if ! diskinfo=\"$(diskutil info \"$disk\")\"; then\n continue\n fi\n\n device=\"$(echo \"$diskinfo\" | get_key \"Device Node\")\"\n\n # See http://superuser.com/q/631592\n raw_device=\"${device//disk/rdisk}\"\n\n description=\"$(echo \"$diskinfo\" | get_key \"Device / Media Name\")\"\n volume_name=\"$(echo \"$diskinfo\" | get_key \"Volume Name\")\"\n removable=\"$(echo \"$diskinfo\" | get_key \"Removable Media\")\"\n protected=\"$(echo \"$diskinfo\" | get_key \"Read-Only Media\")\"\n location=\"$(echo \"$diskinfo\" | get_key \"Device Location\")\"\n size=\"$(echo \"$diskinfo\" | sed 's/Disk Size/Total Size/g' | get_key \"Total Size\" | cut -d '(' -f 2 | cut -d ' ' -f 1)\"\n\n mountpoints=\"$(echo \"$mount_output\" | grep -E \"^${disk}(s[0-9]+)? on \" | cut -d ' ' -f 3)\"\n\n # Omit mounted DMG images\n if [[ \"$description\" == \"Disk Image\" ]]; then\n continue\n fi\n\n echo \"enumerator: diskutil\"\n echo \"busType: UNKNOWN\"\n echo \"busVersion: \\\"0.0\\\"\"\n echo \"device: $device\"\n echo \"raw: $raw_device\"\n\n if [[ $volume_name =~ .*Not\\ applicable.* ]]; then\n echo \"description: \\\"$description\\\"\"\n else\n echo \"description: \\\"$volume_name - $description\\\"\"\n fi\n\n echo \"error: null\"\n echo \"size: $size\"\n echo \"blockSize: null\"\n echo \"logicalBlockSize: null\"\n\n if [[ -z \"$mountpoints\" ]]; then\n echo \"mountpoints: []\"\n else\n echo \"mountpoints:\"\n echo \"$mountpoints\" | while read -r mountpoint ; do\n echo \" - path: \\\"$mountpoint\\\"\"\n done\n fi\n\n if [[ \"$protected\" == \"Yes\" ]]; then\n echo \"isReadOnly: True\"\n else\n echo \"isReadOnly: False\"\n fi\n\n if [[ \"$device\" == \"/dev/disk0\" ]] || \\\n [[ ( \"$removable\" == \"No\" ) || (\"$removable\" == \"Fixed\") ]] || \\\n [[ ( \"$location\" =~ \"Internal\" ) && ( \"$removable\" != \"Yes\" ) && ( \"$removable\" != \"Removable\" ) ]] || \\\n echo \"$mountpoints\" | grep \"^/$\"\n then\n echo \"isSystem: True\"\n else\n echo \"isSystem: False\"\n fi\n\n echo \"isVirtual: null\"\n echo \"isRemovable: null\"\n echo \"isCard: null\"\n echo \"isSCSI: null\"\n echo \"isUSB: null\"\n echo \"isUAS: null\"\n\n echo \"\"\ndone\n",
"content": "#!/bin/bash\n\nset -u\nset -e\n\nget_key() {\n\n # This expression is intentionally unquoted so that\n # multiple lines get joined as a single one.\n # See https://github.com/resin-io-modules/drivelist/pull/129\n echo $(grep \"$1\" | awk -F \" +\" '{ print $3 }')\n\n}\n\nget_until_paren() {\n awk 'match($0, \"\\\\(|$\"){ print substr($0, 0, RSTART - 1) }'\n}\n\nDISKS=\"$(diskutil list | grep '^\\/' | get_until_paren)\"\nmount_output=\"$(mount)\"\n\nfor disk in $DISKS; do\n\n # Ignore drives that were just unplugged\n if ! diskinfo=\"$(diskutil info \"$disk\")\"; then\n continue\n fi\n\n device=\"$(echo \"$diskinfo\" | get_key \"Device Node\")\"\n\n # See http://superuser.com/q/631592\n raw_device=\"${device//disk/rdisk}\"\n\n description=\"$(echo \"$diskinfo\" | get_key \"Device / Media Name\")\"\n volume_name=\"$(echo \"$diskinfo\" | get_key \"Volume Name\")\"\n removable=\"$(echo \"$diskinfo\" | get_key \"Removable Media\")\"\n protected=\"$(echo \"$diskinfo\" | get_key \"Read-Only Media\")\"\n location=\"$(echo \"$diskinfo\" | get_key \"Device Location\")\"\n size=\"$(echo \"$diskinfo\" | sed 's/Disk Size/Total Size/g' | get_key \"Total Size\" | cut -d '(' -f 2 | cut -d ' ' -f 1)\"\n\n mountpoints=\"$(echo \"$mount_output\" | grep -E \"^${disk}(s[0-9]+)? on \" | sed -r -e \"s| \\([^\\(]+$||\" -e \"s|^${disk}(s[0-9]+)? on ||\")\"\n\n # Omit mounted DMG images\n if [[ \"$description\" == \"Disk Image\" ]]; then\n continue\n fi\n\n echo \"enumerator: diskutil\"\n echo \"busType: UNKNOWN\"\n echo \"busVersion: \\\"0.0\\\"\"\n echo \"device: $device\"\n echo \"raw: $raw_device\"\n\n if [[ $volume_name =~ .*Not\\ applicable.* ]]; then\n echo \"description: \\\"$description\\\"\"\n else\n echo \"description: \\\"$volume_name - $description\\\"\"\n fi\n\n echo \"error: null\"\n echo \"size: $size\"\n echo \"blockSize: null\"\n echo \"logicalBlockSize: null\"\n\n if [[ -z \"$mountpoints\" ]]; then\n echo \"mountpoints: []\"\n else\n echo \"mountpoints:\"\n echo \"$mountpoints\" | while read -r mountpoint ; do\n echo \" - path: \\\"$mountpoint\\\"\"\n done\n fi\n\n if [[ \"$protected\" == \"Yes\" ]]; then\n echo \"isReadOnly: True\"\n else\n echo \"isReadOnly: False\"\n fi\n\n if [[ \"$device\" == \"/dev/disk0\" ]] || \\\n [[ ( \"$removable\" == \"No\" ) || (\"$removable\" == \"Fixed\") ]] || \\\n [[ ( \"$location\" =~ \"Internal\" ) && ( \"$removable\" != \"Yes\" ) && ( \"$removable\" != \"Removable\" ) ]] || \\\n echo \"$mountpoints\" | grep \"^/$\"\n then\n echo \"isSystem: True\"\n else\n echo \"isSystem: False\"\n fi\n\n echo \"isVirtual: null\"\n echo \"isRemovable: null\"\n echo \"isCard: null\"\n echo \"isSCSI: null\"\n echo \"isUSB: null\"\n echo \"isUAS: null\"\n\n echo \"\"\ndone\n",
"originalFilename": "darwin.sh",
"type": "text"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drivelist",
"version": "6.0.0",
"version": "6.0.1",
"description": "List all connected drives in your computer, in all major operating systems",
"main": "lib/drivelist.js",
"homepage": "https://github.com/resin-io-modules/drivelist",
Expand Down
2 changes: 1 addition & 1 deletion scripts/darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for disk in $DISKS; do
location="$(echo "$diskinfo" | get_key "Device Location")"
size="$(echo "$diskinfo" | sed 's/Disk Size/Total Size/g' | get_key "Total Size" | cut -d '(' -f 2 | cut -d ' ' -f 1)"

mountpoints="$(echo "$mount_output" | grep -E "^${disk}(s[0-9]+)? on " | cut -d ' ' -f 3)"
mountpoints="$(echo "$mount_output" | grep -E "^${disk}(s[0-9]+)? on " | sed -r -e "s| \([^\(]+$||" -e "s|^${disk}(s[0-9]+)? on ||")"

# Omit mounted DMG images
if [[ "$description" == "Disk Image" ]]; then
Expand Down

0 comments on commit 750cc1c

Please sign in to comment.