Description:
locks dir based on temp file, does not copy dir when copying scripts, added proper rescue for ln_s
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r103:933325ce824a - - 4 files changed: 4 inserted, 3 deleted
@@ -16,25 +16,25 | |||
|
16 | 16 | module DirInit |
|
17 | 17 | |
|
18 | 18 | class Manager |
|
19 | 19 | |
|
20 | 20 | def initialize(dir_name, usage_filename='.usage_counter') |
|
21 | 21 | @dir_name = dir_name |
|
22 | 22 | @usage_filename = usage_filename |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | # Check if someone has initialized the dir. If not, call block. |
|
26 | 26 | |
|
27 | 27 | def setup # :yields: block |
|
28 | - dir = File.new(@dir_name) | |
|
28 | + dir = File.new(@dir_name + '/lockfile',"w+") | |
|
29 | 29 | dir.flock(File::LOCK_EX) |
|
30 | 30 | begin |
|
31 | 31 | counter_filename = get_counter_filename |
|
32 | 32 | if File.exist? counter_filename |
|
33 | 33 | # someone is here |
|
34 | 34 | f = File.new(counter_filename,"r+") |
|
35 | 35 | counter = f.read.to_i |
|
36 | 36 | f.seek(0) |
|
37 | 37 | f.write("#{counter+1}\n") |
|
38 | 38 | f.close |
|
39 | 39 | else |
|
40 | 40 | # i'm the first, create the counter file |
@@ -127,24 +127,25 | |||
|
127 | 127 | def copy_script(problem_home) |
|
128 | 128 | script_dir = "#{problem_home}/script" |
|
129 | 129 | std_script_dir = get_std_script_dir |
|
130 | 130 | |
|
131 | 131 | raise "std-script directory not found" if !FileTest.exist?(std_script_dir) |
|
132 | 132 | |
|
133 | 133 | scripts = Dir[std_script_dir + '/*'] |
|
134 | 134 | |
|
135 | 135 | copied = [] |
|
136 | 136 | |
|
137 | 137 | scripts.each do |s| |
|
138 | 138 | fname = File.basename(s) |
|
139 | + next if FileTest.directory?(s) | |
|
139 | 140 | if !FileTest.exist?("#{script_dir}/#{fname}") |
|
140 | 141 | copied << fname |
|
141 | 142 | FileUtils.cp(s, "#{script_dir}") |
|
142 | 143 | end |
|
143 | 144 | end |
|
144 | 145 | |
|
145 | 146 | return copied |
|
146 | 147 | end |
|
147 | 148 | |
|
148 | 149 | def copy_log_filename(problem_home) |
|
149 | 150 | return File.join(problem_home, '.scripts_copied') |
|
150 | 151 | end |
@@ -1,23 +1,23 | |||
|
1 | 1 | # |
|
2 | 2 | # This part contains various test_request helpers for interfacing |
|
3 | 3 | # with Grader::Engine. There are TestRequestRoomMaker and |
|
4 | 4 | # TestRequestReporter. |
|
5 | 5 | |
|
6 | 6 | module Grader |
|
7 | 7 | |
|
8 | 8 | def self.link_or_copy(src, des) |
|
9 | 9 | begin |
|
10 | 10 | FileUtils.ln_s(src, des) |
|
11 | - rescue | |
|
11 | + rescue NotImplementedError | |
|
12 | 12 | FileUtils.cp(src,des) |
|
13 | 13 | end |
|
14 | 14 | end |
|
15 | 15 | |
|
16 | 16 | def self.call_and_log(error_message) |
|
17 | 17 | begin |
|
18 | 18 | yield |
|
19 | 19 | rescue |
|
20 | 20 | msg = "ERROR: #{error_message}" |
|
21 | 21 | raise msg |
|
22 | 22 | end |
|
23 | 23 | end |
You need to be logged in to leave comments.
Login now