p4_web_api 2014.2.0.pre4 → 2014.2.0.pre5
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.
- checksums.yaml +4 -4
- data/lib/p4_web_api/app/files.rb +19 -7
- data/lib/p4_web_api/change_helper.rb +4 -1
- data/lib/p4_web_api/p4_util.rb +25 -0
- data/lib/p4_web_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7448a94ecf26d4514482e503978244ad96ae7b41
|
4
|
+
data.tar.gz: ccc6efa9cdbac3f0d7c3c1a0ddfd96ac8d83c4fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30370200a5b0cd8bc25059088d453f61e75fe73f58e666fe9e51be0ead4538a14a0ce8e5a3c581ffc5576bcc5af620921775ad8046d03e7af757efd15877c320
|
7
|
+
data.tar.gz: e0f03da79600b959d7385a46086e94dab1b03a4b8e273476ad02bc5950306ea1a9f0ccc462955bb2615b5d9481520df028b2e80f2a83e9b85ede7a8248b8876d
|
data/lib/p4_web_api/app/files.rb
CHANGED
@@ -12,14 +12,23 @@ module P4WebAPI
|
|
12
12
|
class App < Sinatra::Base
|
13
13
|
# Special depots only variant to match no path
|
14
14
|
get '/v1/files' do
|
15
|
+
path = params['path']
|
16
|
+
|
15
17
|
results = nil
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
if path
|
20
|
+
open_p4 do |p4|
|
21
|
+
path = "//#{path}" unless path =~ %r{^//}
|
22
|
+
results = p4.run_files(path)
|
23
|
+
end
|
24
|
+
normalize_files(results) if settings.normalize_output
|
25
|
+
else
|
26
|
+
open_p4 do |p4|
|
27
|
+
results = p4.run_depots
|
28
|
+
end
|
29
|
+
normalize_depots(results) if settings.normalize_output
|
19
30
|
end
|
20
31
|
|
21
|
-
normalize_depots(results) if settings.normalize_output
|
22
|
-
|
23
32
|
results.to_json
|
24
33
|
end
|
25
34
|
|
@@ -34,6 +43,8 @@ module P4WebAPI
|
|
34
43
|
get '/v1/files/*' do
|
35
44
|
dirs = params[:splat].select { |x| !x.empty? }
|
36
45
|
|
46
|
+
P4Util.assert_no_special_paths(dirs)
|
47
|
+
|
37
48
|
results = nil
|
38
49
|
|
39
50
|
open_p4 do |p4|
|
@@ -101,9 +112,10 @@ module P4WebAPI
|
|
101
112
|
description = params['Description'] || 'Uploaded files'
|
102
113
|
is_dir = params.key?('Files')
|
103
114
|
|
115
|
+
P4Util.assert_no_special_paths(path_parts)
|
116
|
+
|
104
117
|
files = nil
|
105
118
|
if is_dir
|
106
|
-
# TODO: 'clean' the directory path, avoiding refs like '...'
|
107
119
|
dir_root = "//#{path_parts.join('/')}"
|
108
120
|
|
109
121
|
files = params['Files'].map do |f|
|
@@ -113,7 +125,6 @@ module P4WebAPI
|
|
113
125
|
}
|
114
126
|
end
|
115
127
|
else
|
116
|
-
# TODO: 'sanitize' this file path
|
117
128
|
files = [
|
118
129
|
{
|
119
130
|
'DepotFile' => "//#{path_parts.join('/')}",
|
@@ -142,7 +153,8 @@ module P4WebAPI
|
|
142
153
|
description = params['Description'] || 'Deleting file'
|
143
154
|
path_parts = params[:splat].select { |x| !x.empty? }
|
144
155
|
|
145
|
-
|
156
|
+
P4Util.assert_no_special_paths(path_parts)
|
157
|
+
|
146
158
|
file_path = "//#{path_parts.join('/')}"
|
147
159
|
|
148
160
|
open_p4_temp_client([file_path]) do |p4|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'base64'
|
2
2
|
|
3
|
+
require_relative 'p4_util'
|
4
|
+
|
3
5
|
module P4WebAPI
|
4
6
|
# This class assists in creating changelists based on an array of file
|
5
7
|
# changes, some of which may be file uploads.
|
@@ -86,7 +88,7 @@ module P4WebAPI
|
|
86
88
|
end
|
87
89
|
|
88
90
|
def exists?
|
89
|
-
!file_result.nil?
|
91
|
+
!file_result.nil? && file_result['action'] != 'delete'
|
90
92
|
end
|
91
93
|
|
92
94
|
#
|
@@ -104,6 +106,7 @@ module P4WebAPI
|
|
104
106
|
end
|
105
107
|
|
106
108
|
def upload_file(p4, change_id, client_root)
|
109
|
+
P4Util.assert_no_special_paths(@depot_file.split('/'))
|
107
110
|
if exists?
|
108
111
|
P4Util.mark_change('edit', p4, change_id, client_root, depot_file)
|
109
112
|
P4Util.save_content(client_root, depot_file, content)
|
data/lib/p4_web_api/p4_util.rb
CHANGED
@@ -59,6 +59,31 @@ module P4WebAPI
|
|
59
59
|
fail P4WebAPI::P4Error.new(err.msgid, err.severity, err.to_s)
|
60
60
|
end
|
61
61
|
|
62
|
+
# Assert that no relative directory or Perforce wildcard is in use for each
|
63
|
+
# string in the `paths` array.
|
64
|
+
def self.assert_no_special_paths(paths)
|
65
|
+
paths.each do |path|
|
66
|
+
if P4Util.wildcard?(path)
|
67
|
+
fail P4Error.default_error("The path '#{path}' contains a Perforce "\
|
68
|
+
'wildcard, which is not allowed')
|
69
|
+
end
|
70
|
+
if P4Util.relative_dir?(path)
|
71
|
+
fail P4Error.default_error("The path '#{path}' is a relative " \
|
72
|
+
'directory, which is not allowed')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns true when `str` contains a Perforce wildcard
|
78
|
+
def self.wildcard?(str)
|
79
|
+
(str =~ /\.\.\./ || str =~ /\*/) != nil
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns true if str is '.' or '..'
|
83
|
+
def self.relative_dir?(str)
|
84
|
+
str == '.' || str == '..'
|
85
|
+
end
|
86
|
+
|
62
87
|
# Returns true if the string looks like a Perforce authentication ticket.
|
63
88
|
def self.p4_ticket?(str)
|
64
89
|
/^[a-zA-Z0-9]{32,}$/.match(str) != nil
|
data/lib/p4_web_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: p4_web_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2014.2.0.
|
4
|
+
version: 2014.2.0.pre5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perforce Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|