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



5
6
7
8
9
10
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
# File 'ext/tms/tms.c', line 5

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 rb_str_new2(path);
	} else {
		return Qnil;
	}
}

.computer_nameObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'ext/tms/tms.c', line 39

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

	CFStringEncoding encoding;
	CFStringRef cfName;

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

		CFRelease(cfName);

		return rb_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
# 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
  backup_a = Backup.list[a_id] or abort("No backup #{a}")
  backup_b = Backup.list[b_id] or abort("No backup #{b}")
  Comparison.new(backup_a, backup_b).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