Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save goyox86/474845 to your computer and use it in GitHub Desktop.
Save goyox86/474845 to your computer and use it in GitHub Desktop.
From 4e9139b57ddd5920e7e993fad0d9e59f36ab18aa Mon Sep 17 00:00:00 2001
From: Jose Narvaez <goyox86@gmail.com>
Date: Tue, 13 Jul 2010 20:29:11 -0430
Subject: [PATCH] File#truncate now raises an IOError if file is not opened for writing
---
kernel/common/file.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/common/file.rb b/kernel/common/file.rb
index e1602ea..143061b 100644
--- a/kernel/common/file.rb
+++ b/kernel/common/file.rb
@@ -1002,9 +1002,9 @@ class File < IO
def truncate(length)
length = Type.coerce_to(length, Integer, :to_int)
+ ensure_open_and_writable
raise Errno::EINVAL, "Can't truncate a file to a negative length" if length < 0
- raise IOError, "File is closed" if closed?
-
+
n = POSIX.ftruncate(@descriptor, length)
Errno.handle if n == -1
n
--
1.7.0.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment