Skip to content

Commit f37c286

Browse files
committed
Boot - move older init.rb into new config dir if possible
1 parent 7177365 commit f37c286

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

app/server/ruby/bin/sonic-pi-server.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@
7171
## exist so the user has a starting point for
7272
## modifying them.
7373

74+
75+
begin
76+
if File.exists?(original_init_path)
77+
if (File.exists?(init_path))
78+
STDOUT.puts "Warning, you have an older init.rb file in #{original_init_path} which is now being ignored as your newer config/init.rb file is being used insted. Consider deleting your old init.rb (perhaps copying anything useful across first)."
79+
else
80+
STDOUT.puts "Found init.rb in old location #{original_init_path}. Moving it to the new config directory #{init_path}."
81+
FileUtils.mv(original_init_path, init_path)
82+
end
83+
end
84+
rescue Exception => e
85+
STDOUT.puts "Warning: exception when comparing new and original init.rb paths"
86+
STDOUT.puts "Error message received:\n-----------------------"
87+
STDOUT.puts e.message
88+
STDOUT.puts e.backtrace.inspect
89+
STDOUT.puts e.backtrace
90+
end
91+
92+
93+
94+
7495
Dir["#{user_config_examples_path}/*"].each do |f|
7596
basename = File.basename(f)
7697
full_config_path = File.absolute_path("#{config_path}/#{basename}")

app/server/ruby/lib/sonicpi/util.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ def init_path
264264
File.absolute_path("#{config_path}/init.rb")
265265
end
266266

267+
def original_init_path
268+
File.absolute_path("#{home_dir_path}/init.rb")
269+
end
270+
267271
def project_path
268272
@@project_path
269273
end

0 commit comments

Comments
 (0)