Created
July 14, 2010 01:05
-
-
Save goyox86/474845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 4e9139b57ddd5920e7e993fad0d9e59f36ab18aa Mon Sep 17 00:00:00 2001 | |
From: Jose Narvaez <[email protected]> | |
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