prevent Gollum::Wiki instances from creating new pages that overwrite pages with the same name.

This commit is contained in:
rick
2010-08-16 07:56:46 -07:00
parent ee04dd84aa
commit c69a5f80dd
4 changed files with 46 additions and 9 deletions
+14
View File
@@ -58,5 +58,19 @@ module Gollum
'img' => {'href' => ['http', 'https', :relative]}
}
}
class Error < StandardError; end
class DuplicatePageError < Error
attr_accessor :dir
attr_accessor :existing_path
attr_accessor :attempted_path
def initialize(dir, existing, attempted, message = nil)
@dir = dir
@existing_path = existing
@attempted_path = attempted
super(message || "Cannot write #{@dir}/#{@attempted_path}, found #{@dir}/#{@existing_path}.")
end
end
end
+13 -2
View File
@@ -315,13 +315,24 @@ module Gollum
ext = @page_class.format_to_ext(format)
path = @page_class.cname(name) + '.' + ext
parts = dir.split('/')
parts = dir.split('/')
container = nil
parts.each do |part|
container = map[part]
end
(container || map)[path] = normalize(data)
container ||= map
downpath = path.downcase
downpath.sub! /\.\w+$/, ''
container.keys.each do |existing|
file = existing.downcase
file.sub! /\.\w+$/, ''
if downpath == file
raise DuplicatePageError.new(dir, existing, path)
end
end
container[path] = normalize(data)
map
end