crystal-community / icr

Interactive console for Crystal programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Icr shows errors next instruction after calling Dir.mkdir(), Dir.mkdir_p() and Dir.rmdir()

crabonature opened this issue · comments

When I try to use Dir.mkdir() in icr the next instructions always will fail with error complaining about it exists. From source code it's just trying to run mkdir() on every recompilation and thats why error shows.

The same goes for Dir.rmdir() and Dir.mkdir_p().

crabonature@crap:~[130]$ icr

icr(0.24.1) > Dir.mkdir("bla bla")
 => 0

icr(0.24.1) > 1 + 1
Unable to create directory 'bla bla': File exists (Errno)
  from Dir::mkdir<String, Int32>:Int32
  from Dir::mkdir<String>:Int32
  from __icr_exec__:Int32
  from __crystal_main
  from _crystal_main<Int32, Pointer(Pointer(UInt8))>:Nil
  from Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil
  from Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32
  from main

This is interesting. It seems this works fine for me in version 0.4.0, but I do get this error in 0.5.0. I'm not sure what changed exactly between the two, but that may be worth investigating.

Strange that it could works before because in code there is reevaluation of whole command stack when every new command is issued, so it was probably always error for second rmdir("xx") evaluation, because this dir was removed at previous instruction evaluation.

File.write(@tmp_file_path, @command_stack.to_code)

This line of execution changed since 0.4.0, because of Crystal changes:
status = Process.run(command, shell: true, output: io_out, error: io_error)