File tree Expand file tree Collapse file tree 6 files changed +31
-4
lines changed Expand file tree Collapse file tree 6 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ def ensure_written_file
52
52
ensure_file ( written_file )
53
53
end
54
54
55
+ def ensure_not_overwriting_existing_file
56
+ ensure_not_file ( written_file )
57
+ end
58
+
55
59
def find_by_path ( path )
56
60
files = case namespace
57
61
when "collections"
@@ -72,6 +76,14 @@ def ensure_file(file)
72
76
render_404 if file . nil?
73
77
end
74
78
79
+ def ensure_not_file ( file )
80
+ return if file . nil?
81
+
82
+ Jekyll . logger . warn "Jekyll Admin:" , "Could not create file."
83
+ Jekyll . logger . warn "" , "Path #{ file . relative_path . inspect } already exists!"
84
+ render_404
85
+ end
86
+
75
87
def ensure_directory
76
88
render_404 unless Dir . exist? ( directory_path )
77
89
end
Original file line number Diff line number Diff line change @@ -51,6 +51,11 @@ def renamed?
51
51
ensure_leading_slash ( request_payload [ "path" ] ) != relative_path
52
52
end
53
53
54
+ # Is this request creating a new file?
55
+ def new?
56
+ !request_payload [ "path" ]
57
+ end
58
+
54
59
private
55
60
56
61
# Returns the path to the requested file's containing directory
Original file line number Diff line number Diff line change @@ -25,8 +25,11 @@ class Server < Sinatra::Base
25
25
put "/:collection_id/*?/?:path.:ext" do
26
26
ensure_collection
27
27
28
- if renamed?
28
+ if new?
29
+ ensure_not_overwriting_existing_file
30
+ elsif renamed?
29
31
ensure_requested_file
32
+ ensure_not_overwriting_existing_file
30
33
delete_file_without_process path
31
34
end
32
35
Original file line number Diff line number Diff line change @@ -16,8 +16,11 @@ class Server < Sinatra::Base
16
16
put "/*?/?:path.:ext" do
17
17
ensure_html_content
18
18
19
- if renamed?
19
+ if new?
20
+ ensure_not_overwriting_existing_file
21
+ elsif renamed?
20
22
ensure_requested_file
23
+ ensure_not_overwriting_existing_file
21
24
delete_file_without_process path
22
25
end
23
26
Original file line number Diff line number Diff line change @@ -16,13 +16,15 @@ class Server < Sinatra::Base
16
16
put "/*?/?:path.:ext" do
17
17
ensure_html_content
18
18
19
- if renamed?
19
+ if new?
20
+ ensure_not_overwriting_existing_file
21
+ elsif renamed?
20
22
ensure_requested_file
23
+ ensure_not_overwriting_existing_file
21
24
delete_file_without_process path
22
25
end
23
26
24
27
write_file write_path , page_body
25
-
26
28
json written_file . to_api ( :include_content => true )
27
29
end
28
30
Original file line number Diff line number Diff line change @@ -267,6 +267,7 @@ def app
267
267
write_file "_posts/2016-01-01-test2.md"
268
268
269
269
request = {
270
+ :path => "_posts/2016-01-01-test2.md" ,
270
271
:front_matter => { :foo => "bar2" } ,
271
272
:raw_content => "test" ,
272
273
}
@@ -283,6 +284,7 @@ def app
283
284
write_file "_posts/more posts/2016-01-01-test2.md"
284
285
285
286
request = {
287
+ :path => "_posts/more posts/2016-01-01-test2.md" ,
286
288
:front_matter => { :foo => "bar2" } ,
287
289
:raw_content => "test" ,
288
290
}
You can’t perform that action at this time.
0 commit comments