-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for get disk serial number on darwin #1791
base: master
Are you sure you want to change the base?
add support for get disk serial number on darwin #1791
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! I haven't tested it myself, but using the JSON output of system_profiler
seems like a good approach. I've left a few comments, so I'd appreciate it if you could address them.
@@ -88,8 +91,60 @@ func getFsType(stat unix.Statfs_t) string { | |||
return common.ByteToString(stat.Fstypename[:]) | |||
} | |||
|
|||
type SPNVMeDataTypeItem struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change to a private struct?
func SerialNumberWithContext(ctx context.Context, name string) (string, error) { | ||
return "", common.ErrNotImplementedError | ||
cmd := exec.Command("system_profiler", "SPNVMeDataType", "-json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change to use invoker.CommandWithContext() like here?
err = json.Unmarshal(output, &temp) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to unmarshal JSON: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = json.Unmarshal(output, &temp) | |
if err != nil { | |
return "", fmt.Errorf("failed to unmarshal JSON: %w", err) | |
} | |
if err := json.Unmarshal(output, &temp); err != nil { | |
return "", fmt.Errorf("failed to unmarshal JSON: %w", err) | |
} |
var temp struct { | ||
SPNVMeDataType []struct { | ||
Items []SPNVMeDataTypeItem `json:"_items"` | ||
} `json:"SPNVMeDataType"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about defining the struct at the top level instead of dynamically defining it here?
Hello! This is my first PR on this project, so let me know if I got anything wrong and should change it.
This fixes #801 and adds support for getting (NVMe) drives' serial number. It does this by executing system_profiler and unmarshalling.