mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-20 20:39:06 +00:00
Use diskutil on macOS to extract volume name and path for FAT mounts (#4928)
* Use diskutil on macOS to extract volume name and path for FAT mounts * Improve FAT mount detection on macOS by parsing diskutil output into a map * Simplify conditional check
This commit is contained in:
@@ -1013,15 +1013,50 @@ func findFATMounts(options *compileopts.Options) ([]mountPoint, error) {
|
|||||||
return nil, fmt.Errorf("could not list mount points: %w", err)
|
return nil, fmt.Errorf("could not list mount points: %w", err)
|
||||||
}
|
}
|
||||||
for _, elem := range list {
|
for _, elem := range list {
|
||||||
// TODO: find a way to check for the filesystem type.
|
volumePath := filepath.Join("/Volumes", elem.Name())
|
||||||
// (Only return FAT filesystems).
|
if _, err := os.Stat(volumePath); err != nil {
|
||||||
points = append(points, mountPoint{
|
continue
|
||||||
name: elem.Name(),
|
}
|
||||||
path: filepath.Join("/Volumes", elem.Name()),
|
|
||||||
})
|
cmd := exec.Command("diskutil", "info", volumePath)
|
||||||
|
var out bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
continue // skip if diskutil failed
|
||||||
|
}
|
||||||
|
|
||||||
|
diskInfo := map[string]string{}
|
||||||
|
scanner := bufio.NewScanner(&out)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
parts := strings.SplitN(line, ":", 2)
|
||||||
|
if len(parts) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key := strings.TrimSpace(parts[0])
|
||||||
|
value := strings.TrimSpace(parts[1])
|
||||||
|
diskInfo[key] = value
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
volName, okv := diskInfo["Volume Name"]
|
||||||
|
fsType, okf := diskInfo["File System Personality"]
|
||||||
|
if !okv || !okf {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a filesystem type is FAT-based
|
||||||
|
if strings.Contains(strings.ToUpper(fsType), "FAT") {
|
||||||
|
points = append(points, mountPoint{
|
||||||
|
name: volName,
|
||||||
|
path: volumePath,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sort.Slice(points, func(i, j int) bool {
|
sort.Slice(points, func(i, j int) bool {
|
||||||
return points[i].path < points[j].name
|
return points[i].path < points[j].path
|
||||||
})
|
})
|
||||||
return points, nil
|
return points, nil
|
||||||
case "linux":
|
case "linux":
|
||||||
|
|||||||
Reference in New Issue
Block a user