Skip to content

Commit 217de3c

Browse files
committed
flag dirname match as potential filename conflict
1 parent d08c837 commit 217de3c

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

gui/blueprint.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ function NamePanel:detect_name_collision()
126126

127127
local paths = dfhack.filesystem.listdir_recursive('blueprints', nil, false)
128128
for _,v in ipairs(paths) do
129-
if v.path:startswith(name) and
130-
v.path:sub(suffix_pos,suffix_pos):find('[.-]') then
129+
if (v.isdir and v.path..'/' == name) or
130+
(v.path:startswith(name) and
131+
v.path:sub(suffix_pos,suffix_pos):find('[.-]')) then
131132
self.has_name_collision = true
132133
return
133134
end

test/gui/blueprint.lua

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ local function send_keys(...)
2929
end
3030

3131
local function load_ui()
32-
local view = b.BlueprintUI{}
32+
local options = {}
33+
blueprint.parse_gui_commandline(options, {})
34+
local view = b.BlueprintUI{presets=options}
3335
view:show()
3436
return view
3537
end
@@ -394,6 +396,22 @@ function test.name_no_collision()
394396
expect.eq('Set', get_screen_word(name_help_text_pos))
395397
send_keys('LEAVESCREEN') -- cancel ui
396398
end)
399+
400+
mock.patch(dfhack.filesystem, 'listdir_recursive',
401+
mock.func({{path='blueprint'}}),
402+
function()
403+
local view = load_ui()
404+
view.subviews.name.text = 'blueprint/'
405+
view.subviews.name.on_change()
406+
view:updateLayout()
407+
local name_help_label = view.subviews.name_help
408+
local name_help_text_pos = {x=name_help_label.frame_body.x1,
409+
y=name_help_label.frame_body.y1}
410+
view:onRender()
411+
expect.eq('Set', get_screen_word(name_help_text_pos),
412+
'dirname does not conflict with similar filename')
413+
send_keys('LEAVESCREEN') -- cancel ui
414+
end)
397415
end
398416

399417
function test.name_collision()
@@ -409,6 +427,22 @@ function test.name_collision()
409427
expect.eq('Warning:', get_screen_word(name_help_text_pos))
410428
send_keys('LEAVESCREEN') -- cancel ui
411429
end)
430+
431+
mock.patch(dfhack.filesystem, 'listdir_recursive',
432+
mock.func({{path='blueprint', isdir=true}}),
433+
function()
434+
local view = load_ui()
435+
view.subviews.name.text = 'blueprint/'
436+
view.subviews.name.on_change()
437+
view:updateLayout()
438+
local name_help_label = view.subviews.name_help
439+
local name_help_text_pos = {x=name_help_label.frame_body.x1,
440+
y=name_help_label.frame_body.y1}
441+
view:onRender()
442+
expect.eq('Warning:', get_screen_word(name_help_text_pos),
443+
'dirname match generates warning')
444+
send_keys('LEAVESCREEN') -- cancel ui
445+
end)
412446
end
413447

414448
-- widgets to configure which blueprint phases to output

0 commit comments

Comments
 (0)