Method: Etch::Client#get_orig_contents

Defined in:
lib/etch/client.rb

#get_orig_contents(file) ⇒ Object



1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
# File 'lib/etch/client.rb', line 1628

def get_orig_contents(file)
  origpath = save_orig(file)
  orig_contents = nil
  # We only send back the actual original file contents if the original is
  # a regular file, otherwise we send back an empty string.
  if (origpath =~ /\.ORIG$/ || origpath =~ /\.TMP$/) &&
     File.file?(origpath) && !File.symlink?(origpath)
    # As elsewhere we have no idea how arbitrary files that the user is
    # managing are encoded, so tell Ruby to read the file in binary mode.
    orig_contents = nil
    if RUBY_VERSION.split('.')[0..1].join('.').to_f >= 1.9
      orig_contents = IO.read(origpath, :encoding => 'ASCII-8BIT')
    else
      orig_contents = IO.read(origpath)
    end
  else
    orig_contents = ''
  end
  orig_contents
end