Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

pkg/fileutil: helper function to get major, minor numbers of a device file #3500

Merged
merged 1 commit into from
Jan 6, 2017

Conversation

squeed
Copy link
Contributor

@squeed squeed commented Dec 23, 2016

No description provided.

}
stat_t, ok := d.Sys().(*syscall.Stat_t)
if !ok {
err = fmt.Errorf("Cannot determine device number")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase error

@@ -105,3 +106,35 @@ func Lsetxattr(path string, attr string, data []byte, flags int) error {
}
return nil
}

// GetDeviceInfo returns the type, major, and minor numbers of a device
func GetDeviceInfo(path string) (kind rune, major uint64, minor uint64, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to

func GetDeviceInfo(path string) (kind rune, major uint64, minor uint64, err error) {
   	d, err := os.Lstat(path)
  	if err != nil {
  		return ' ', 0, 0, err
  	}
        return getDeviceInfo(d)
}

func getDeviceInfo(d *os.FileInfo) (kind rune, major uint64, minor uint64, err error) {
...
}

Then you can test the inner function to your heart's content

@lucab
Copy link
Member

lucab commented Jan 5, 2017

Ci complains about:

fileutil_test.go:260: arg i for printf verb %s of wrong type: int

@lucab lucab added this to the v1.23.0 milestone Jan 5, 2017
@squeed
Copy link
Contributor Author

squeed commented Jan 5, 2017

@jonboulle care to re-review?

@jonboulle
Copy link
Contributor

Seems OK but I'll defer to @lucab for approval

Copy link
Member

@lucab lucab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Depending on who will be the consumers of this, it could make sense to later introduce a custom enum for the kind instead of a char.

@lucab lucab merged commit 82044c5 into rkt:master Jan 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants