RAliasFile 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +3 -0
- data/FILES +12 -0
- data/LICENSE +21 -0
- data/README +49 -0
- data/README.html +43 -0
- data/ext/extconf.rb +32 -0
- data/ext/raliasfile.c +131 -0
- data/raliasfile.gemspec +33 -0
- data/sample/make_alias.scpt +0 -0
- data/sample/sample_raliasfile.rb +61 -0
- data/test/make_alias.scpt +0 -0
- data/test/test_raliasfile.rb +94 -0
- metadata +58 -0
data/ChangeLog
ADDED
data/FILES
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2006 Yvon Thoraval
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
5
|
+
copy of this software and associated documentation files (the "Software"),
|
6
|
+
to deal in the Software without restriction, including without limitation
|
7
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included
|
12
|
+
in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
17
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
19
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
20
|
+
DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= Ruby RAliasFile C extension
|
2
|
+
|
3
|
+
This extension allows Ruby programs, running over MacOS X 10.4+,
|
4
|
+
to use Alias Manager for resolving aliases files.
|
5
|
+
Currently, that includes alias file resolution.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Download and install the latest package from the rubyforge.org
|
10
|
+
RubyGems repository.
|
11
|
+
|
12
|
+
gem install raliasfile --remote
|
13
|
+
gem check raliasfile --test
|
14
|
+
|
15
|
+
If the tests all pass, you're ready to start using sendfile.
|
16
|
+
|
17
|
+
Or, if you don't have rubygems installed, you can install by
|
18
|
+
hand by downloading the tarball:
|
19
|
+
|
20
|
+
tar xzvf raliasfile-<latest>.tar.gz
|
21
|
+
cd raliasfile-<latest>/ext
|
22
|
+
ruby extconf.rb
|
23
|
+
make
|
24
|
+
sudo make install
|
25
|
+
|
26
|
+
You can then run the tests with:
|
27
|
+
|
28
|
+
ruby test/test_raliasfile.rb
|
29
|
+
|
30
|
+
== Usage
|
31
|
+
|
32
|
+
A small example is given in sample/sample.rb.
|
33
|
+
|
34
|
+
== Usefull Readings
|
35
|
+
|
36
|
+
"ADC Home > Reference Library > Guides > Cocoa > File Management > Low-Level File Management Programming Topics >" : "Resolving Aliases" http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html
|
37
|
+
"Technical Note FL30" : "Resolving Alias Files Quietly" http://developer.apple.com/technotes/fl/fl_30.html
|
38
|
+
|
39
|
+
== Contact Information
|
40
|
+
|
41
|
+
This project's homepage is:
|
42
|
+
|
43
|
+
http://rubyforge.org/projects/raliasfile/
|
44
|
+
|
45
|
+
Thereupon are additional resources, such as news and forums
|
46
|
+
can be found for working out any issues you may have with this
|
47
|
+
Ruby extension. In the last case, you can email questions or patches
|
48
|
+
to yvon_thoraval@mac.com.
|
49
|
+
|
data/README.html
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
6
|
+
<head>
|
7
|
+
<title>README</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1><a name="label-0" id="label-0">Ruby RAliasFile C extension</a></h1><!-- RDLabel: "Ruby RAliasFile C extension" -->
|
11
|
+
<p>This extension allows Ruby programs, running over MacOS X 10.4+,
|
12
|
+
to use Alias Manager for resolving aliases files.
|
13
|
+
Currently, that includes alias file resolution.</p>
|
14
|
+
<h2><a name="label-1" id="label-1">Installation</a></h2><!-- RDLabel: "Installation" -->
|
15
|
+
<p>Download and install the latest package from the rubyforge.org
|
16
|
+
RubyGems repository.</p>
|
17
|
+
<pre>gem install raliasfile --remote
|
18
|
+
gem check raliasfile --test</pre>
|
19
|
+
<p>If the tests all pass, you're ready to start using sendfile.</p>
|
20
|
+
<p>Or, if you don't have rubygems installed, you can install by
|
21
|
+
hand by downloading the tarball:</p>
|
22
|
+
<pre>tar xzvf raliasfile-<latest>.tar.gz
|
23
|
+
cd raliasfile-<latest>/ext
|
24
|
+
ruby extconf.rb
|
25
|
+
make
|
26
|
+
sudo make install</pre>
|
27
|
+
<p>You can then run the tests with:</p>
|
28
|
+
<pre>ruby test/test_raliasfile.rb</pre>
|
29
|
+
<h2><a name="label-2" id="label-2">Usage</a></h2><!-- RDLabel: "Usage" -->
|
30
|
+
<p>A small example is given in sample/sample.rb.</p>
|
31
|
+
<h2><a name="label-3" id="label-3">Usefull Readings</a></h2><!-- RDLabel: "Usefull Readings" -->
|
32
|
+
<pre>"ADC Home > Reference Library > Guides > Cocoa > File Management > Low-Level File Management Programming Topics >" : "Resolving Aliases" http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html
|
33
|
+
"Technical Note FL30" : "Resolving Alias Files Quietly" http://developer.apple.com/technotes/fl/fl_30.html</pre>
|
34
|
+
<h2><a name="label-4" id="label-4">Contact Information</a></h2><!-- RDLabel: "Contact Information" -->
|
35
|
+
<p>This project's homepage is:</p>
|
36
|
+
<pre>http://rubyforge.org/projects/raliasfile/</pre>
|
37
|
+
<p>Thereupon are additional resources, such as news and forums
|
38
|
+
can be found for working out any issues you may have with this
|
39
|
+
Ruby extension. In the last case, you can email questions or patches
|
40
|
+
to yvon_thoraval@mac.com.</p>
|
41
|
+
|
42
|
+
</body>
|
43
|
+
</html>
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Loads mkmf which is used to make makefiles for Ruby extensions
|
3
|
+
require 'mkmf'
|
4
|
+
|
5
|
+
case RUBY_PLATFORM
|
6
|
+
when /powerpc-darwin8.7.0/
|
7
|
+
$CFLAGS << " -I /System/Library/Frameworks/Carbon.framework/Headers "
|
8
|
+
$CFLAGS << " -I /System/Library/Frameworks/CoreFoundation.framework/Headers "
|
9
|
+
$CFLAGS << " -I /System/Library/Frameworks/CoreServices.framework/Headers "
|
10
|
+
#$CFLAGS << " -I /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers "
|
11
|
+
$CFLAGS << " -I /System/Library/Frameworks/Foundation.framework/Headers "
|
12
|
+
$CFLAGS << " -I /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers "
|
13
|
+
$CFLAGS << " -fnested-functions "
|
14
|
+
#$LDFLAGS << " -framework OSServices"
|
15
|
+
$LDFLAGS << " -framework CoreFoundation "
|
16
|
+
$LDFLAGS << " -framework Carbon "
|
17
|
+
#$LDFLAGS << " -framework CoreFoundation Carbon"
|
18
|
+
$LDFLAGS << " -framework CoreServices "
|
19
|
+
#$LDFLAGS << " -framework CoreFoundation CoreServices"
|
20
|
+
$LDFLAGS << " -framework Foundation "
|
21
|
+
|
22
|
+
# Give it a name
|
23
|
+
extension_name = 'raliasfile'
|
24
|
+
|
25
|
+
# The destination
|
26
|
+
dir_config(extension_name)
|
27
|
+
|
28
|
+
# Do the work
|
29
|
+
create_makefile(extension_name)
|
30
|
+
else
|
31
|
+
puts "This Ruby extension needs MacOS X 10.4+"
|
32
|
+
end
|
data/ext/raliasfile.c
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
//
|
2
|
+
// RAliasFile.c
|
3
|
+
//
|
4
|
+
|
5
|
+
#include <CoreFoundation/CoreFoundation.h>
|
6
|
+
#include <Carbon/Carbon.h>
|
7
|
+
#include <CFURL.h>
|
8
|
+
#include <ruby.h>
|
9
|
+
|
10
|
+
VALUE RAliasFile = Qnil;
|
11
|
+
VALUE cRAliasFile;
|
12
|
+
VALUE alias_path;
|
13
|
+
|
14
|
+
VALUE m_raliasfile_init(VALUE self, VALUE alias_path)
|
15
|
+
{
|
16
|
+
//printf("From C => alias_path : %s\n", StringValuePtr(alias_path));
|
17
|
+
char resolved_path[256] = "";
|
18
|
+
VALUE is_alias_file=Qfalse;
|
19
|
+
VALUE path_exists=Qfalse;
|
20
|
+
VALUE was_aliased=Qfalse;
|
21
|
+
VALUE folder=Qfalse;
|
22
|
+
VALUE data_file=Qfalse;
|
23
|
+
VALUE broken=Qtrue;
|
24
|
+
CFStringRef path = CFStringCreateWithCString(kCFAllocatorDefault, StringValuePtr(alias_path), kCFStringEncodingUTF8);
|
25
|
+
CFURLRef url = NULL;
|
26
|
+
url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path, 0, Qfalse);
|
27
|
+
if (url != NULL) {
|
28
|
+
FSRef theRef;
|
29
|
+
if (CFURLGetFSRef(url, &theRef)) {
|
30
|
+
path_exists=Qtrue;
|
31
|
+
Boolean wasAliased;
|
32
|
+
Boolean targetIsFolder;
|
33
|
+
Boolean aliasFileFlag;
|
34
|
+
Boolean folderFlag;
|
35
|
+
FSIsAliasFile (&theRef, &aliasFileFlag, &folderFlag);
|
36
|
+
if(aliasFileFlag) {
|
37
|
+
is_alias_file=Qtrue;
|
38
|
+
}
|
39
|
+
FSResolveAliasFile(&theRef, true /*resolveAliasChains*/, &targetIsFolder, &wasAliased);
|
40
|
+
CFURLRef resolvedUrl = CFURLCreateFromFSRef(NULL, &theRef);
|
41
|
+
if (resolvedUrl != NULL) {
|
42
|
+
CFStringRef theResolvedAliasPath = CFURLCopyFileSystemPath(resolvedUrl, kCFURLPOSIXPathStyle);
|
43
|
+
Boolean success = CFStringGetCString(theResolvedAliasPath, resolved_path, 256, kCFStringEncodingUTF8);
|
44
|
+
if(wasAliased) {
|
45
|
+
was_aliased=Qtrue;
|
46
|
+
} else {
|
47
|
+
was_aliased=Qfalse;
|
48
|
+
}
|
49
|
+
if (targetIsFolder && wasAliased) {
|
50
|
+
folder=Qtrue;
|
51
|
+
data_file=Qfalse;
|
52
|
+
}
|
53
|
+
if (!targetIsFolder && wasAliased) {
|
54
|
+
folder=Qfalse;
|
55
|
+
data_file=Qtrue;
|
56
|
+
}
|
57
|
+
if(aliasFileFlag && wasAliased) {
|
58
|
+
broken=Qfalse;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
rb_iv_set(self, "@alias_path", alias_path);
|
64
|
+
rb_iv_set(self, "@path_exists", path_exists);
|
65
|
+
rb_iv_set(self, "@is_alias_file", is_alias_file);
|
66
|
+
rb_iv_set(self, "@is_alias_broken", broken);
|
67
|
+
rb_iv_set(self, "@was_aliased", was_aliased);
|
68
|
+
rb_iv_set(self, "@resolved_path", rb_str_new2(resolved_path));
|
69
|
+
rb_iv_set(self, "@folder", folder);
|
70
|
+
rb_iv_set(self, "@data_file", data_file);
|
71
|
+
CFRelease(path);
|
72
|
+
CFRelease(url);
|
73
|
+
return self;
|
74
|
+
}
|
75
|
+
|
76
|
+
VALUE m_set_alias_path(VALUE self, VALUE _alias_path) {
|
77
|
+
alias_path = _alias_path;
|
78
|
+
rb_iv_set(self, "@alias_path", alias_path);
|
79
|
+
}
|
80
|
+
|
81
|
+
VALUE m_path_exists(VALUE self) {
|
82
|
+
return rb_iv_get(self, "@path_exists");
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE m_alias_path(VALUE self) {
|
86
|
+
return rb_iv_get(self, "@alias_path");
|
87
|
+
}
|
88
|
+
|
89
|
+
VALUE m_alias_file(VALUE self) {
|
90
|
+
return rb_iv_get(self, "@is_alias_file");
|
91
|
+
}
|
92
|
+
|
93
|
+
VALUE m_alias_broken(VALUE self) {
|
94
|
+
return rb_iv_get(self, "@is_alias_broken");
|
95
|
+
}
|
96
|
+
|
97
|
+
VALUE m_resolved_path(VALUE self) {
|
98
|
+
return rb_iv_get(self, "@resolved_path");
|
99
|
+
}
|
100
|
+
|
101
|
+
VALUE m_was_aliased(VALUE self) {
|
102
|
+
return rb_iv_get(self, "@was_aliased");
|
103
|
+
}
|
104
|
+
|
105
|
+
VALUE m_is_folder(VALUE self) {
|
106
|
+
return rb_iv_get(self, "@folder");
|
107
|
+
}
|
108
|
+
|
109
|
+
VALUE m_is_file(VALUE self) {
|
110
|
+
return rb_iv_get(self, "@data_file");
|
111
|
+
}
|
112
|
+
|
113
|
+
VALUE m_version(VALUE self) {
|
114
|
+
char *version = "0.0.1";
|
115
|
+
return rb_str_new2(version);
|
116
|
+
}
|
117
|
+
|
118
|
+
void Init_raliasfile() {
|
119
|
+
cRAliasFile = rb_define_class("RAliasFile", rb_cObject);
|
120
|
+
rb_define_method(RAliasFile, "initialize", m_raliasfile_init, 1);
|
121
|
+
rb_define_method(RAliasFile, "path_exists?", m_path_exists, 0);
|
122
|
+
rb_define_method(RAliasFile, "is_alias_file?", m_alias_file, 0);
|
123
|
+
rb_define_method(RAliasFile, "is_alias_broken?", m_alias_broken, 0);
|
124
|
+
rb_define_method(RAliasFile, "alias_path=", m_set_alias_path, 1);
|
125
|
+
rb_define_method(RAliasFile, "alias_path", m_alias_path, 0);
|
126
|
+
rb_define_method(RAliasFile, "resolved_path", m_resolved_path, 0);
|
127
|
+
rb_define_method(RAliasFile, "was_aliased?", m_was_aliased, 0);
|
128
|
+
rb_define_method(RAliasFile, "is_folder_alias?", m_is_folder, 0);
|
129
|
+
rb_define_method(RAliasFile, "is_file_alias?", m_is_file, 0);
|
130
|
+
rb_define_method(RAliasFile, "version", m_version, 0);
|
131
|
+
}
|
data/raliasfile.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# raliasfile.gemspec
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.name = 'RAliasFile'
|
9
|
+
s.version = "0.0.1"
|
10
|
+
# s.platform = Gem::Platform::RUBY::OSX
|
11
|
+
# s.platform = Gem::Platform::OSX
|
12
|
+
s.summary = "C ext to Ruby aimed to resolve alias file on Mac OS X 10.4+"
|
13
|
+
s.requirements << 'MacOS X 10.4+'
|
14
|
+
s.files = File.read( 'FILES').split( $/)
|
15
|
+
s.test_files = Dir.glob('test/test_*.rb') + Dir.glob('test/*.scpt')
|
16
|
+
s.extensions << 'ext/extconf.rb'
|
17
|
+
s.has_rdoc = false
|
18
|
+
s.author = "Yvon Thoraval"
|
19
|
+
s.email = "yvon_thoraval@mac.com"
|
20
|
+
s.rubyforge_project = "RAliasFile"
|
21
|
+
s.homepage = "http://rubyforge.org/projects/raliasfile/"
|
22
|
+
s.description = <<-EOF
|
23
|
+
RAliasFile is a C extension to Ruby aimed to resolve alias file on Mac OS X 10.4+.
|
24
|
+
It also provides means to check if the alias file is broken,
|
25
|
+
it's target is a folder or file, the given path does exists.
|
26
|
+
EOF
|
27
|
+
s.required_ruby_version = '>= 1.8.4'
|
28
|
+
end
|
29
|
+
|
30
|
+
if $0==__FILE__
|
31
|
+
Gem.manage_gems
|
32
|
+
Gem::Builder.new(spec).build
|
33
|
+
end
|
Binary file
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# sample.rb
|
4
|
+
#
|
5
|
+
|
6
|
+
#require File.dirname(Dir.pwd)+"/osx/raliasfile/raliasfile"
|
7
|
+
require 'raliasfile'
|
8
|
+
|
9
|
+
DESKTOP=ENV['HOME']+"/Desktop"
|
10
|
+
TEST_DIR="#{DESKTOP}/raliasfile_tests"
|
11
|
+
ORG_DIR="#{TEST_DIR}/alias/orig"
|
12
|
+
BRK_DIR="#{TEST_DIR}/alias/orig/broken"
|
13
|
+
ALS_DIR="#{TEST_DIR}/alias"
|
14
|
+
|
15
|
+
`mkdir -p "#{BRK_DIR}/broken"`
|
16
|
+
`touch "#{BRK_DIR}/broken.txt"`
|
17
|
+
|
18
|
+
`mkdir -p "#{ORG_DIR}/good"`
|
19
|
+
`touch "#{ORG_DIR}/good.txt"`
|
20
|
+
|
21
|
+
# build array of "true" aliases
|
22
|
+
to_alias=[]
|
23
|
+
to_alias << "#{BRK_DIR}/broken"
|
24
|
+
to_alias << "#{BRK_DIR}/broken.txt"
|
25
|
+
to_alias << "#{ORG_DIR}/good"
|
26
|
+
to_alias << "#{ORG_DIR}/good.txt"
|
27
|
+
|
28
|
+
# build "true" aliases using Finder
|
29
|
+
to_alias.each {|a| `osascript make_alias.scpt "#{a}" "#{File.basename(a)}" "#{ALS_DIR}"`}
|
30
|
+
|
31
|
+
# remove "broken" dir to simulate broken aliases
|
32
|
+
`rm -rf "#{BRK_DIR}"`
|
33
|
+
# if you comment out the above line the aliases of "broken" dir won't be broken
|
34
|
+
|
35
|
+
# array of sample pathes
|
36
|
+
aliases=[]
|
37
|
+
aliases << "#{ALS_DIR}/broken" # broken alias from target folder
|
38
|
+
aliases << "#{ALS_DIR}/broken.txt" # broken alias from target file
|
39
|
+
aliases << "#{ALS_DIR}/good" # good alias from target folder
|
40
|
+
aliases << "#{ALS_DIR}/good.txt" # good alias from target file
|
41
|
+
aliases << "#{ORG_DIR}/good" # wrong alias being a folder
|
42
|
+
aliases << "#{ORG_DIR}/good.txt" # wrong alias being a file
|
43
|
+
aliases << "#{ALS_DIR}/bid/good" # wrong path to alias being a folder
|
44
|
+
aliases << "#{ALS_DIR}/bid/good.txt" # wrong path to alias being a file
|
45
|
+
|
46
|
+
# "resolve" every sample pathes exploring all the methods
|
47
|
+
aliases.each {|al|
|
48
|
+
a=RAliasFile.new(al)
|
49
|
+
puts "\n"
|
50
|
+
puts "a.alias_path="+a.alias_path
|
51
|
+
puts "a.path_exists?="+a.path_exists?.to_s
|
52
|
+
puts "a.is_alias_file?="+a.is_alias_file?.to_s
|
53
|
+
puts "a.is_alias_broken?="+a.is_alias_broken?.to_s
|
54
|
+
puts "a.resolved_path="+a.resolved_path
|
55
|
+
puts "a.was_aliased?="+a.was_aliased?.to_s
|
56
|
+
puts "a.is_folder_alias?="+a.is_folder_alias?.to_s
|
57
|
+
puts "a.is_file_alias?="+a.is_file_alias?.to_s
|
58
|
+
}
|
59
|
+
|
60
|
+
# uncomment following line if you won't leave anything on your Desktop
|
61
|
+
#`rm -rf "#{TEST_DIR}"`
|
Binary file
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# test_raliasfile.rb
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'rubyunit'
|
7
|
+
require File.dirname(Dir.pwd)+"/osx/raliasfile/raliasfile"
|
8
|
+
|
9
|
+
class RAliasFileTest < RUNIT::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
# setup used dirs
|
13
|
+
@test_dir="/private/tmp/raliasfile_tests"
|
14
|
+
@org_dir="#{@test_dir}/alias/orig"
|
15
|
+
@brk_dir="#{@test_dir}/alias/orig/broken"
|
16
|
+
@als_dir="#{@test_dir}/alias"
|
17
|
+
|
18
|
+
# buid folder ans files to alias
|
19
|
+
`mkdir -p "#{@brk_dir}/broken"`
|
20
|
+
`touch "#{@brk_dir}/broken.txt"`
|
21
|
+
`mkdir -p "#{@org_dir}/good"`
|
22
|
+
`touch "#{@org_dir}/good.txt"`
|
23
|
+
|
24
|
+
# build array of "true" aliases
|
25
|
+
to_alias=[]
|
26
|
+
to_alias << "#{@brk_dir}/broken"
|
27
|
+
to_alias << "#{@brk_dir}/broken.txt"
|
28
|
+
to_alias << "#{@org_dir}/good"
|
29
|
+
to_alias << "#{@org_dir}/good.txt"
|
30
|
+
|
31
|
+
# build "true" aliases using Finder
|
32
|
+
to_alias.each {|a| `osascript make_alias.scpt "#{a}" "#{File.basename(a)}" "#{@als_dir}"`}
|
33
|
+
|
34
|
+
# remove "broken" dir to simulate broken aliases
|
35
|
+
`rm -rf "#{@brk_dir}"`
|
36
|
+
|
37
|
+
# array of sample aliases path
|
38
|
+
@aliases=[]
|
39
|
+
@aliases << "#{@als_dir}/broken"
|
40
|
+
@aliases << "#{@als_dir}/broken.txt"
|
41
|
+
@aliases << "#{@als_dir}/good"
|
42
|
+
@aliases << "#{@als_dir}/good.txt"
|
43
|
+
@aliases << "#{@org_dir}/good"
|
44
|
+
@aliases << "#{@org_dir}/good.txt"
|
45
|
+
@aliases << "#{@als_dir}/bid/good"
|
46
|
+
@aliases << "#{@als_dir}/bid/good.txt"
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_alias
|
50
|
+
# "resolve" every sample aliases path exploring all the methods
|
51
|
+
@aliases.each {|al|
|
52
|
+
a=RAliasFile.new(al)
|
53
|
+
fil=(/.*\.txt$/ === al)
|
54
|
+
brk=(/.*broken.*/ === al)
|
55
|
+
org=(/.*\/orig\/.*/ === al)
|
56
|
+
bid=(/.*\/bid\/.*/ === al)
|
57
|
+
orig=(brk)? "#{@brk_dir}/broken" : ((org)? "#{@org_dir}/good" : ((bid)? "#{@als_dir}/bid/good" : "#{@org_dir}/good"))
|
58
|
+
orig=orig+((fil)? ".txt" : "")
|
59
|
+
path_exists=(bid)? false : true
|
60
|
+
alias_file=(org || bid)? false : true
|
61
|
+
broken=(brk || org || bid)? true : false
|
62
|
+
was_aliased=(brk || org || bid)? false : true
|
63
|
+
file_alias=(fil && was_aliased)? true : false
|
64
|
+
folder_alias=(!fil && was_aliased)? true : false
|
65
|
+
assert al === a.alias_path
|
66
|
+
assert path_exists === a.path_exists?
|
67
|
+
assert alias_file === a.is_alias_file?
|
68
|
+
assert broken === a.is_alias_broken?
|
69
|
+
assert (orig === a.resolved_path) || (brk || org || bid)
|
70
|
+
assert was_aliased === a.was_aliased?
|
71
|
+
assert folder_alias === a.is_folder_alias?
|
72
|
+
assert file_alias === a.is_file_alias?
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def teardown
|
77
|
+
# clean up temp dir
|
78
|
+
`rm -rf "#{@test_dir}"`
|
79
|
+
STDERR.puts "\n"
|
80
|
+
STDERR.puts "----- Now Finish RAliasFileTest -----"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
=begin
|
85
|
+
Usage :
|
86
|
+
> ruby test_raliasfile.rb
|
87
|
+
|
88
|
+
Typical output :
|
89
|
+
RAliasFileTest#test_alias
|
90
|
+
----- Now Finish RAliasFileTest -----
|
91
|
+
.
|
92
|
+
Time: 1.255557
|
93
|
+
OK (1/1 tests 64 asserts)
|
94
|
+
=end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: RAliasFile
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2006-08-30 00:00:00 +02:00
|
8
|
+
summary: C ext to Ruby aimed to resolve alias file on Mac OS X 10.4+
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: yvon_thoraval@mac.com
|
12
|
+
homepage: http://rubyforge.org/projects/raliasfile/
|
13
|
+
rubyforge_project: RAliasFile
|
14
|
+
description: RAliasFile is a C extension to Ruby aimed to resolve alias file on Mac OS X 10.4+. It also provides means to check if the alias file is broken, it's target is a folder or file, the given path does exists.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.4
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Yvon Thoraval
|
31
|
+
files:
|
32
|
+
- FILES
|
33
|
+
- README
|
34
|
+
- README.html
|
35
|
+
- LICENSE
|
36
|
+
- ChangeLog
|
37
|
+
- ext/extconf.rb
|
38
|
+
- ext/raliasfile.c
|
39
|
+
- test/make_alias.scpt
|
40
|
+
- test/test_raliasfile.rb
|
41
|
+
- sample/make_alias.scpt
|
42
|
+
- sample/sample_raliasfile.rb
|
43
|
+
- raliasfile.gemspec
|
44
|
+
test_files:
|
45
|
+
- test/test_raliasfile.rb
|
46
|
+
- test/make_alias.scpt
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
extra_rdoc_files: []
|
50
|
+
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions:
|
54
|
+
- ext/extconf.rb
|
55
|
+
requirements:
|
56
|
+
- MacOS X 10.4+
|
57
|
+
dependencies: []
|
58
|
+
|