@@ -147,72 +147,82 @@ module.exports.listBlockDevices = function() {
147
147
child_process . execFile ( "lsblk" , [ "--bytes" , "--pairs" , "--output" , columns ] , function ( error , stdout , stderr ) {
148
148
if ( error ) {
149
149
reject ( "Failed to lsblk " + stdout + " " + stderr ) ;
150
- } else {
150
+ return ;
151
+ }
152
+
153
+ let
154
+ devices = [ ] ;
155
+
156
+ for ( let line of stdout . split ( "\n" ) ) {
151
157
let
152
- devices = [ ] ;
153
-
154
- for ( let line of stdout . split ( "\n" ) ) {
158
+ parameters = line . match ( / ( ^ | \s ) [ A - Z - _ ] + = " [ ^ " \n ] * " / g ) ;
159
+
160
+ if ( parameters ) {
155
161
let
156
- parameters = line . match ( / ( ^ | \s ) [ A - Z - ] + = " [ ^ " \n ] * " / g ) ;
157
-
158
- if ( parameters ) {
162
+ device = { } ;
163
+
164
+ for ( let parameter of parameters ) {
159
165
let
160
- device = { } ;
161
-
162
- for ( let parameter of parameters ) {
163
- let
164
- matches = parameter . match ( / ^ \s * ( [ A - Z - ] + ) = " ( [ ^ " \n ] * ) " $ / ) ;
165
-
166
- device [ matches [ 1 ] ] = matches [ 2 ] ;
167
- }
168
-
169
- /* If the parent device's name is the prefix of ours, use our suffix as the short name of
170
- * this partition
171
- */
172
- if ( supportsPKNAME ) {
173
- if ( device . PKNAME . length > 0 && device . NAME . indexOf ( device . PKNAME ) === 0 ) {
174
- device . PARTNAME = device . NAME . substring ( device . PKNAME . length ) ;
175
- } else if ( device . TYPE === "disk" ) {
176
- device . PARTNAME = "" ;
177
- } else {
178
- device . PARTNAME = device . NAME ;
179
- }
166
+ matches = parameter . match ( / ^ \s * ( [ A - Z - _ ] + ) = " ( [ ^ " \n ] * ) " $ / ) ;
167
+
168
+ device [ matches [ 1 ] ] = matches [ 2 ] ;
169
+ }
170
+
171
+ /* If the parent device's name is the prefix of ours, use our suffix as the short name of
172
+ * this partition
173
+ */
174
+ if ( supportsPKNAME ) {
175
+ if ( device . PKNAME . length > 0 && device . NAME . indexOf ( device . PKNAME ) === 0 ) {
176
+ device . PARTNAME = device . NAME . substring ( device . PKNAME . length ) ;
177
+ } else if ( device . TYPE === "disk" ) {
178
+ device . PARTNAME = "" ;
179
+ } else {
180
+ device . PARTNAME = device . NAME ;
180
181
}
181
-
182
- device . DEVICEPATH = "/dev/" + device . NAME ;
183
- device . SIZE = parseInt ( device . SIZE ) ;
184
- device [ "LOG-SEC" ] = parseInt ( device [ "LOG-SEC" ] ) ;
185
- device [ "PHY-SEC" ] = parseInt ( device [ "PHY-SEC" ] ) ;
186
-
187
- devices . push ( device ) ;
188
182
}
183
+
184
+ device . DEVICEPATH = "/dev/" + device . NAME ;
185
+ device . SIZE = parseInt ( device . SIZE , 10 ) ;
186
+
187
+ /* lsblk has started renaming these columns to use an underscore, so grab
188
+ * the values from the new location if so:
189
+ * https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/1961542
190
+ */
191
+
192
+ device [ "LOG-SEC" ] = parseInt ( device [ "LOG_SEC" ] || device [ "LOG-SEC" ] , 10 ) ;
193
+ device [ "PHY-SEC" ] = parseInt ( device [ "PHY_SEC" ] || device [ "PHY-SEC" ] , 10 ) ;
194
+
195
+ delete device [ "LOG_SEC" ] ;
196
+ delete device [ "PHY_SEC" ] ;
197
+
198
+ devices . push ( device ) ;
189
199
}
190
-
191
- if ( ! supportsPKNAME ) {
192
- for ( let device of devices ) {
193
- // We could synthesize a PKNAME from our best-guess, but it's probably better not to:
194
- device . PKNAME = "" ;
195
- // Fall back to just using the name of the device if we can't come up with anything shorter
196
- device . PARTNAME = device . NAME ;
197
-
198
- switch ( device . TYPE ) {
199
- case "part" :
200
- let
201
- parentDisk = devices . find ( parent => parent . TYPE === "disk" && device . NAME . indexOf ( parent . NAME ) === 0 ) ;
202
-
203
- if ( parentDisk ) {
204
- device . PARTNAME = device . NAME . substring ( parentDisk . NAME . length ) ;
205
- }
206
- break ;
207
- case "disk" :
208
- device . PARTNAME = "" ;
209
- break ;
210
- }
200
+ }
201
+
202
+ if ( ! supportsPKNAME ) {
203
+ for ( let device of devices ) {
204
+ // We could synthesize a PKNAME from our best-guess, but it's probably better not to:
205
+ device . PKNAME = "" ;
206
+ // Fall back to just using the name of the device if we can't come up with anything shorter
207
+ device . PARTNAME = device . NAME ;
208
+
209
+ switch ( device . TYPE ) {
210
+ case "part" :
211
+ let
212
+ parentDisk = devices . find ( parent => parent . TYPE === "disk" && device . NAME . indexOf ( parent . NAME ) === 0 ) ;
213
+
214
+ if ( parentDisk ) {
215
+ device . PARTNAME = device . NAME . substring ( parentDisk . NAME . length ) ;
216
+ }
217
+ break ;
218
+ case "disk" :
219
+ device . PARTNAME = "" ;
220
+ break ;
211
221
}
212
222
}
213
-
214
- resolve ( devices ) ;
215
223
}
224
+
225
+ resolve ( devices ) ;
216
226
} ) ;
217
227
} ) ) ) ;
218
228
} ;
0 commit comments