NewDevMapper creates a new instance of the DOS device replacer.
()
| 43 | |
| 44 | // NewDevMapper creates a new instance of the DOS device replacer. |
| 45 | func NewDevMapper() DevMapper { |
| 46 | m := &mapper{ |
| 47 | cache: make(map[string]string), |
| 48 | } |
| 49 | |
| 50 | // loop through logical drives and query the DOS device name |
| 51 | for _, drive := range sys.GetLogicalDrives() { |
| 52 | device, err := sys.QueryDosDevice(drive) |
| 53 | if err != nil { |
| 54 | continue |
| 55 | } |
| 56 | m.cache[device] = drive |
| 57 | } |
| 58 | |
| 59 | // resolve the SystemRoot environment variable |
| 60 | m.sysroot = os.Getenv("SystemRoot") |
| 61 | if m.sysroot == "" { |
| 62 | m.sysroot = os.Getenv("SYSTEMROOT") |
| 63 | } |
| 64 | |
| 65 | return m |
| 66 | } |
| 67 | |
| 68 | func (m *mapper) Convert(filename string) string { |
| 69 | if filename == "" || len(filename) < deviceOffset { |