Skip to content

Commit

Permalink
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/helpers/file_helper.rb
Original file line number Diff line number Diff line change
@@ -305,14 +305,18 @@ def qpdf(path)

#
# Move files between stages - new -> in process -> done
#
def move_files(from_path, to_path, retain_from = false)
# Params:
# - from path = copy from
# - to path = destination
# - retain_from = true if you want to keep from, otherwise it is deleted
# - only_before = date for files to move (only if retain from is true)
def move_files(from_path, to_path, retain_from = false, only_before = nil)
# move into the new dir - and mv files to the in_process_dir
pwd = FileUtils.pwd
begin
FileUtils.mkdir_p(to_path)
Dir.chdir(from_path)
FileUtils.mv Dir.glob('*'), to_path, force: true
FileUtils.mv Dir.glob('*').filter{|fn| !retain_from || only_before.nil? || File.ctime(fn) < only_before}, to_path, force: true
Dir.chdir(to_path)
begin
# remove from_path as files are now "in process"
2 changes: 1 addition & 1 deletion app/models/portfolio_evidence.rb
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ def self.move_to_pid_folder
pid_folder = File.join(student_work_dir(:in_process), "pid_#{Process.pid}")

# Move everything in "new" to "pid" folder but retain the old "new" folder
FileHelper.move_files(student_work_dir(:new), pid_folder, true)
FileHelper.move_files(student_work_dir(:new), pid_folder, true, DateTime.now - 1.minute)
pid_folder
end

0 comments on commit a53a998

Please sign in to comment.