nextSplit returns the filename indicating the next split considering the following splitting rules: - the part number is the string such '.part-XXX' where X is made of [0-9] digits. - the part number is the final component of the filename, it can also be the file extension if there is one. - if a pa
(fname string)
| 282 | // be split considering those rules. |
| 283 | // - filename must not be empty |
| 284 | func nextSplit(fname string) (next string, first bool, err error) { |
| 285 | if fname == "" { |
| 286 | err = errors.New("empty filename") |
| 287 | return |
| 288 | } |
| 289 | |
| 290 | m := splitFnameRx.FindAllStringSubmatch(fname, -1) |
| 291 | if m == nil { |
| 292 | // Create first split |
| 293 | ext := filepath.Ext(fname) |
| 294 | fnoext := strings.TrimSuffix(fname, ext) |
| 295 | return fmt.Sprintf("%s-part-1%s", fnoext, ext), true, nil |
| 296 | } |
| 297 | |
| 298 | // Find and increment current part number |
| 299 | nosplit := m[0][1] |
| 300 | partnum, _ := strconv.Atoi(m[0][2]) |
| 301 | ext := m[0][3] |
| 302 | |
| 303 | if partnum == 0 { |
| 304 | return "", false, fmt.Errorf("%q: incorrect split", fname) |
| 305 | } |
| 306 | |
| 307 | return fmt.Sprintf("%s-part-%d%s", nosplit, partnum+1, ext), false, nil |
| 308 | } |
| 309 | |
| 310 | // fileExists reports whether fname exists and is a regular file. |
| 311 | func fileExists(fname string) bool { |
no outgoing calls