From c1b4f5b80be258a04ab04e6c54242fcf9eaddcb8 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 21 Mar 2014 11:57:33 -0400 Subject: [PATCH] FIX: `sed` on OSX sucks and doesn't work with the same commands as on most Linux machines. This regexp is compatible with both. --- lib/export/exporter.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/export/exporter.rb b/lib/export/exporter.rb index 59f1eeeed2f..4f3fba09b3c 100644 --- a/lib/export/exporter.rb +++ b/lib/export/exporter.rb @@ -199,19 +199,19 @@ module Export # - create the "restore" schema # - prepend the "restore" schema into the search_path - regexp = "^SET search_path = public, pg_catalog;$" + regexp = "SET search_path = public, pg_catalog;" replacement = [ "DROP SCHEMA IF EXISTS restore CASCADE;", "CREATE SCHEMA restore;", "SET search_path = restore, public, pg_catalog;", - ].join("\\n") + ].join(" ") # we only want to replace the VERY first occurence of the search_path command - expression = "0,/#{regexp}/s//#{replacement}/" + expression = "1,/^#{regexp}$/s/#{regexp}/#{replacement}/" # I tried to use the --in-place argument but it was SLOOOWWWWwwwwww # so I output the result into another file and rename it back afterwards - [ "sed --expression='#{expression}' < #{@dump_filename} > #{@dump_filename}.tmp", + [ "sed -e '#{expression}' < #{@dump_filename} > #{@dump_filename}.tmp", "&&", "mv #{@dump_filename}.tmp #{@dump_filename}", ].join(" ")