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
|
# File 'lib/canopus/workspace/edit/executable.rb', line 6
def apply
return {"applied" => false, "failureReason" => "workspace edit plan has already been used"} if @used
@used = true
verify_unchanged
@operations.each do |operation|
@failed_change = operation[:index]
execute_resource(operation)
end
@memory_started = true
@failed_change = nil
update_buffers
@workspace.refresh_files
result = {"applied" => true}
result["recoveryPaths"] = @recoveries.dup unless @recoveries.empty?
announce_recovery
result
rescue StandardError => error
failures = @memory_started ? [] : rollback
announce_recovery
result = {"applied" => false, "failureReason" => ([error.message] + failures).join("; "),
"recoveryPaths" => @recoveries.select { |path| File.exist?(path) || File.symlink?(path) }}
result["failureReason"] += "; recoverable files: #{File.join(@root, '.canopus', 'trash')}" unless result["recoveryPaths"].empty?
result["failedChange"] = @failed_change if @failed_change
result
ensure
close
end
|