New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #548: fix error when renaming folder #552
Changes from 2 commits
8ed3896
6f0f0ec
af73ed4
e46ce2b
62fee1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ def unset_path(rel_path) | |
|
||
def file_data(rel_path) | ||
dirname, basename = Pathname(rel_path).split.map(&:to_s) | ||
if [nil, '', '.'].include? dirname | ||
if [nil, '', '.'].include?(dirname) | ||
@tree[basename] ||= {} | ||
@tree[basename].dup | ||
else | ||
|
@@ -46,16 +46,18 @@ def file_data(rel_path) | |
end | ||
|
||
def dir_entries(rel_path) | ||
subtree = if ['', '.'].include? rel_path.to_s | ||
rel_path_s = rel_path.to_s | ||
subtree = if ['', '.'].include?(rel_path_s) | ||
@tree | ||
else | ||
@tree[rel_path.to_s] ||= _auto_hash | ||
@tree[rel_path.to_s] | ||
@tree[rel_path_s] ||= _auto_hash | ||
end | ||
|
||
subtree.transform_values do |values| | ||
# only get data for file entries | ||
values.key?(:mtime) ? values : {} | ||
subtree.each_with_object({}) do |(key, values), result| | ||
# only return data for file entries | ||
if values.respond_to?(:has_key?) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this extra check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The root of this bug is that for folders the subtree has an array (edit: hash) of hashes (that each respond to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think I could address the above more cleanly a few lines up. Maybe check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out my check for Array wouldn't work, because in fact the top-level object is a hash with the filename as key. The values in turn are hashes with symbols as keys (like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed--it's definitely a hack! I certainly could replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
result[key] = values.has_key?(:mtime) ? values : {} | ||
end | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest moving the assignment into the expression for readability sake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which assignment?
rel_path_s =
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally prefer:
I think it's easier to read and less likely to cause bugs in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. To me, that would be a surprising step away from DRY code. I've found the common assignment can be less bug-prone, for example if an
elsif
is added. And it often identifies a good refactor point where the entireif
/else
cascade can move into a separate method. I'd rather leave this for now.