Module: Tms

Defined in:
lib/tms.rb,
lib/tms/path.rb,
lib/tms/space.rb,
lib/tms/table.rb,
lib/tms/backup.rb,
lib/tms/comparison.rb,
ext/tms/tms.c

Defined Under Namespace

Modules: Space Classes: Backup, Comparison, Path, Table

Class Method Summary collapse

Class Method Details

.backup_volumeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'ext/tms/tms.c', line 11

static VALUE backup_volume(VALUE self){
	OSStatus status = pathTooLongErr;
	char *path;
	size_t pathLength;

	CFDataRef aliasData;
	AliasHandle alias;
	FSRef fs;
	Boolean wasChanged;

	aliasData = CFPreferencesCopyAppValue(CFSTR("BackupAlias"), CFSTR("com.apple.TimeMachine"));
	if (aliasData) {
		if (noErr == PtrToHand(CFDataGetBytePtr(aliasData), (Handle *)&alias, CFDataGetLength(aliasData))) {
			if (noErr == FSResolveAlias(NULL, alias, &fs, &wasChanged)) {
				path = malloc(pathLength = 256);
				while (noErr != (status = FSRefMakePath(&fs, (UInt8*)path, pathLength))) {
					if (pathTooLongErr == status) {
						pathLength += 256;
						path = reallocf(path, pathLength);
					}
				}
			}
			DisposeHandle((Handle)alias);
		}
		CFRelease(aliasData);
	}

	if (noErr == status) {
		return UTF8_STR_NEW2(path);
	} else {
		return Qnil;
	}
}

.computer_nameObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/tms/tms.c', line 45

static VALUE computer_name(VALUE self){
	char *name;
	size_t nameLength;

	CFStringRef cfName;

	if (cfName = SCDynamicStoreCopyComputerName(NULL, NULL)) {
		name = malloc(nameLength = 256);
		while (!CFStringGetCString(cfName, name, nameLength, kCFStringEncodingUTF8)) {
			nameLength += 256;
			name = reallocf(name, nameLength);
		}

		CFRelease(cfName);

		return UTF8_STR_NEW2(name);
	} else {
		return Qnil;
	}
}

.diff(a, b = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tms.rb', line 51

def diff(a, b = nil)
  a_id = backup_id(a)
  if b
    b_id = backup_id(b)
  else
    if Backup.list.length == 1
      abort("Only one backup exist")
    elsif a_id == 0 || (Backup.list[a_id] && !Backup.list[a_id - 1])
      abort("No backup before oldest one")
    else
      a_id, b_id = a_id - 1, a_id
    end
  end

  $stdout.puts "Comparing:"
  by_id = proc do |name, id|
    backup = Backup.list[id] or abort("No backup #{name}")
    $stdout.puts "#{id} #{backup.path}"
    backup
  end
  Comparison.new(by_id[a, a_id], by_id[b, b_id]).run
end

.listObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tms.rb', line 13

def list
  backups = Backup.list
  Table.new do |t|
    t.col '', Backup.colorize? && :red
    t.col '', Backup.colorize? && :blue
    t.col 'num'
    t.col 'name'
    if Backup.show_all_columns
      t.col 'state'
      t.col 'type'
      t.col 'version'
      t.col 'completed in', nil, :right
      t.col 'started at'
      t.col 'finished at'
    end

    backups.each_with_index do |b, i|
      values = [
        i,
        i - backups.length,
        b.number,
        b.name
      ]
      if Backup.show_all_columns
        values += [
          b.state,
          b.type,
          b.version,
          format(b.completed_in, :time),
          format(b.started_at, :date),
          format(b.finished_at, :date)
        ]
      end
      t << values
    end
  end.print
end

.versionObject



9
10
11
# File 'lib/tms.rb', line 9

def version
  Gem.loaded_specs['tms'].version.to_s rescue nil
end