Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Files moved under other files now placed in parent folder

  • Loading branch information...
commit 200b5c0651462113f8b6416ad63eb81b616d696b 1 parent 9da439a
@ddlsmurf authored
Showing with 34 additions and 2 deletions.
  1. +7 −2 lib/fled/file_listing.rb
  2. +27 −0 tests/test_operations.rb
View
9 lib/fled/file_listing.rb
@@ -89,7 +89,7 @@ def operations_from! source_listing
next if path.any? { |o| o[:error] }
if target[:name] != "" && !target[:uid]
operations << [:mk, self.path_of(target).map { |o| o[:name] }]
- fake_source = {:name => target[:name]}
+ fake_source = {:name => target[:name], :dir => true}
fake_source[:parent] = running_source[path.last[:source][:uid]] unless path.empty?
target_uid = "new_#{running_source.count}"
target_uid += "_" while @objects_by_id[target_uid] || running_source[target_uid]
@@ -111,11 +111,16 @@ def operations_from! source_listing
if new_name != target[:name]
pending_renames << [:renamed, target, target[:name]]
end
+ if (target_parent = target[:parent])
+ until !target_parent || !target_parent[:source] || target_parent[:source][:dir]
+ target_parent = target_parent[:parent]
+ end
+ end
source_path = running_source.path_of(source).map { |o| o[:name] }
target[:name] = source[:name] = new_name
operations << [:moved,
source_path,
- self.path_of(target).map { |o| o[:name] }
+ self.path_of(target_parent).map { |o| o[:name] } + [target[:name]]
]
if target[:parent]
source[:parent] = running_source[target[:parent][:uid]]
View
27 tests/test_operations.rb
@@ -165,6 +165,33 @@ def test_reparent
TEST
assert_equal [[:mv, 'folder/sous/truc', 'truc']], ops
end
+ def test_reparent_under_file
+ ops = @fs.operations_if_edited_as <<-TEST
+ folder :0
+ sous :1
+ truc :2
+ truc.txt :3
+ TEST
+ assert_equal [[:mv, "folder/truc.txt", "folder/sous/truc.txt"]], ops
+ end
+ def test_reparent_under_file_at_root
+ ops = TestFS.new do
+ folder(0) {
+ file_one(1)
+ file_two(2)
+ file_three(3)
+ }
+ end.operations_if_edited_as <<-TEST
+ file_one :1
+ file_two :2
+ file_three :3
+ TEST
+ assert_equal [
+ [:mv, "folder/file_one", "file_one"],
+ [:mv, "folder/file_two", "file_two"],
+ [:mv, "folder/file_three", "file_three"],
+ ], ops
+ end
def test_reparent_impact_on_mkdir
ops = @fs.operations_if_edited_as <<-TEST
folder :0
Please sign in to comment.
Something went wrong with that request. Please try again.