| 149 | } |
| 150 | |
| 151 | func listDrives() (workspacesdk.LSResponse, error) { |
| 152 | // disk.Partitions() will return partitions even if there was a failure to |
| 153 | // get one. Any errored partitions will not be returned. |
| 154 | partitionStats, err := disk.Partitions(true) |
| 155 | if err != nil && len(partitionStats) == 0 { |
| 156 | // Only return the error if there were no partitions returned. |
| 157 | return workspacesdk.LSResponse{}, xerrors.Errorf("failed to get partitions: %w", err) |
| 158 | } |
| 159 | |
| 160 | contents := make([]workspacesdk.LSFile, 0, len(partitionStats)) |
| 161 | for _, a := range partitionStats { |
| 162 | // Drive letters on Windows have a trailing separator as part of their name. |
| 163 | // i.e. `os.Open("C:")` does not work, but `os.Open("C:\\")` does. |
| 164 | name := a.Mountpoint + string(os.PathSeparator) |
| 165 | contents = append(contents, workspacesdk.LSFile{ |
| 166 | Name: name, |
| 167 | AbsolutePathString: name, |
| 168 | IsDir: true, |
| 169 | }) |
| 170 | } |
| 171 | |
| 172 | return workspacesdk.LSResponse{ |
| 173 | AbsolutePath: []string{}, |
| 174 | AbsolutePathString: "", |
| 175 | Contents: contents, |
| 176 | }, nil |
| 177 | } |
| 178 | |
| 179 | func pathToArray(path string) []string { |
| 180 | out := strings.FieldsFunc(path, func(r rune) bool { |