info.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const fs = require('fs')
  2. const path = require('path')
  3. const plist = require('plist')
  4. const bplist = require('bplist-parser')
  5. const log = require('../../util/log')
  6. module.exports = {
  7. version: 4,
  8. name: 'backup.info',
  9. description: `Gets a backup's info`,
  10. requiresBackup: true,
  11. // Run on a v3 lib / backup object.
  12. async run (lib, { backup }) {
  13. // Get the path for the info plist.
  14. let infoPath = path.join(backup.path, 'Info.plist')
  15. let fd = fs.openSync(infoPath, 'r')
  16. let buffer = Buffer.alloc(7)
  17. // Read the first 7 bytes into the buffer.
  18. fs.readSync(fd, buffer, 0, 7, 0)
  19. fs.closeSync(fd)
  20. var data
  21. // Binary plists have the marker 'bplist0'
  22. if (buffer.toString('ascii') === 'bplist0') {
  23. // Parse as binary plist
  24. log.verbose('parsing manifest', infoPath)
  25. data = bplist.parseBuffer(fs.readFileSync(infoPath))[0]
  26. // Remove this data, it's kind of useless.
  27. delete data['iTunes Files']
  28. } else {
  29. // Parse as normal plist.
  30. log.verbose('parsing info', infoPath)
  31. data = plist.parse(fs.readFileSync(infoPath, 'utf8'))
  32. delete data['iTunes Files']
  33. }
  34. return data
  35. },
  36. // Public facing properties
  37. output: {
  38. buildVersion: el => el['Build Version'],
  39. deviceName: el => el['Device Name'],
  40. displayName: el => el['Display Name'],
  41. guid: el => el['GUID'],
  42. installedApplications: el => el['Installed Applications'],
  43. lastBackupDate: el => el['Last Backup Date'],
  44. productName: el => el['Product Name'],
  45. productType: el => el['Product Type'],
  46. productVersion: el => el['Product Version'],
  47. serialNumber: el => el['Serial Number'],
  48. targetIdentifier: el => el['Target Identifier'],
  49. targetType: el => el['Target Type'],
  50. uniqueIdentifier: el => el['Unique Identifier'],
  51. iTunesSettings: el => el['iTunes Settings'],
  52. iTunesVersion: el => el['iTunes Version']
  53. }
  54. }