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
5252 ensure_file ( written_file )
5353 end
5454
55+ def ensure_not_overwriting_existing_file
56+ ensure_not_file ( written_file )
57+ end
58+
5559 def find_by_path ( path )
5660 files = case namespace
5761 when "collections"
@@ -72,6 +76,14 @@ def ensure_file(file)
7276 render_404 if file . nil?
7377 end
7478
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+
7587 def ensure_directory
7688 render_404 unless Dir . exist? ( directory_path )
7789 end
Original file line number Diff line number Diff line change @@ -51,6 +51,11 @@ def renamed?
5151 ensure_leading_slash ( request_payload [ "path" ] ) != relative_path
5252 end
5353
54+ # Is this request creating a new file?
55+ def new?
56+ !request_payload [ "path" ]
57+ end
58+
5459 private
5560
5661 # 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
2525 put "/:collection_id/*?/?:path.:ext" do
2626 ensure_collection
2727
28- if renamed?
28+ if new?
29+ ensure_not_overwriting_existing_file
30+ elsif renamed?
2931 ensure_requested_file
32+ ensure_not_overwriting_existing_file
3033 delete_file_without_process path
3134 end
3235
Original file line number Diff line number Diff line change @@ -16,8 +16,11 @@ class Server < Sinatra::Base
1616 put "/*?/?:path.:ext" do
1717 ensure_html_content
1818
19- if renamed?
19+ if new?
20+ ensure_not_overwriting_existing_file
21+ elsif renamed?
2022 ensure_requested_file
23+ ensure_not_overwriting_existing_file
2124 delete_file_without_process path
2225 end
2326
Original file line number Diff line number Diff line change @@ -16,13 +16,15 @@ class Server < Sinatra::Base
1616 put "/*?/?:path.:ext" do
1717 ensure_html_content
1818
19- if renamed?
19+ if new?
20+ ensure_not_overwriting_existing_file
21+ elsif renamed?
2022 ensure_requested_file
23+ ensure_not_overwriting_existing_file
2124 delete_file_without_process path
2225 end
2326
2427 write_file write_path , page_body
25-
2628 json written_file . to_api ( :include_content => true )
2729 end
2830
Original file line number Diff line number Diff line change @@ -267,6 +267,7 @@ def app
267267 write_file "_posts/2016-01-01-test2.md"
268268
269269 request = {
270+ :path => "_posts/2016-01-01-test2.md" ,
270271 :front_matter => { :foo => "bar2" } ,
271272 :raw_content => "test" ,
272273 }
@@ -283,6 +284,7 @@ def app
283284 write_file "_posts/more posts/2016-01-01-test2.md"
284285
285286 request = {
287+ :path => "_posts/more posts/2016-01-01-test2.md" ,
286288 :front_matter => { :foo => "bar2" } ,
287289 :raw_content => "test" ,
288290 }
You can’t perform that action at this time.
0 commit comments