Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loaderror and some other stuff I can't figure out

    Hi,

    I just started to learn Ruby (absolutely love it!), so most basics I
    read up on. I gave myself a simple project, but I got stuck.

    trying to build:
    program that creates 5 .txt files in another dir, while creating this
    dir in the process.

    Code:
    Code:
    Dir.chdir('..')
    Dir.mkdir(File.join('', 'temp_dir'))
    Dir.chdir(File.join('', 'temp_dir'))
    
    @num = 0
    @num = @num.to_i
    
    loop do |file|
      @num = @num.to_s
      filenew = "blabla" + @num + ".txt"
      fileinstance = File.new(filenew, 'w')
      fileinstance.close
      @num = @num.to_i
      @num += 1
    break if
      @num >= 5
    end
    When i execute this via cmd (windows 7) then irb: load 'test.rb'
    it all works fine. Its probably not the shortest way to do it, but it
    got me jumping out of my chair after hours and hours :P

    Though, when i run it again, 2 things happen.
    1st: my irb return:

    Code:
    Code:
    LoadError: cannot load such file -- test.rb
            from (irb):2:in 'load'
            from (irb):2
            from C:/rubystack/ruby/bin/irb:12:in '<main>'
    It seems stuck or something, like I didn't .close something... but I
    did, I think...
    So, when i type quit, open irb again it seems to execute it, but gives
    me problem #2:

    Code:
    Code:
    Errno::EEXIST: File exists - /temp_dir
            etc etc
    Well, its cause it already created the directory right? So, I've been
    trying to write code that works around this:
    code1:

    Code:
    Code:
    Dir.chdir('..')
    Dir.foreach('.') do |dirname|
      if   Dir.exist?("temp_dir")
        Dir.chdir(File.join('', 'temp_dir'))
      else
        Dir.mkdir(File.join('', 'temp_dir'))
        Dir.chdir(File.join('', 'temp_dir'))
      end
    end
    I have been trying so many things here, this is just where I am at right
    now.

    Hopefully someone here can tell me whats wrong here... this |dirname|
    bugs me specifically, cause its just there, but has no use anywhere
    else?
    thanks in advance!

  2. #2
    New Coder
    Join Date
    May 2015
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is very likely that this problem is caused by installation of E Text Editor on Windows 7. In order to provide compatibility with TextMate on Windows, E automatically installs Cygwin. During installation a bash script is run which tries to modify permissions on C:. Here's the line:

    chmod o-w `cygpath $HOMEDRIVE`

    Apparently when Cygwin sets permissions, it is making a mess of the Windows ACL permissions. In order to protect the integrity of the system root drive, Windows UAC does something known as Virtualization or Data Redirection. More info here. In our case, instead of messing up the permissions on the real root directory, Virtualization kicks in and corrupts permissions on the VirtualStore (%localappdata%\VirtualStore) directory instead, making its root inaccessible (although any directories within remain untouched and accessible). When Ruby installs gems it tries to access the root C:\ directory, which UAC disallows, so it tries to access %localappdata%\VirtualStore, which it can't if you have corrupt permissions, thus you get the failure.
    hi


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •