Project

General

Profile

Feature #13743

Support linking of files opened with O_TMPFILE

Added by Glass_saga (Masaki Matsushita) over 1 year ago. Updated over 1 year ago.

Status:
Rejected
Priority:
Normal
Target version:
[ruby-core:82031]

Description

This patch enables linking of files opened with O_TMPFILE into file system.
Users can make a temporary file persistent as named file.

File.open(".", IO::WRONLY|IO::TMPFILE) do |f|
  f.write("content")
  f.chmod(0600)
  File.link(f, "file_name") # make temporary file persistent
end

Files

patch.diff (2.44 KB) patch.diff Glass_saga (Masaki Matsushita), 07/13/2017 11:15 AM

History

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

Extension of File.link, but not File#link?

Updated by normalperson (Eric Wong) over 1 year ago

glass.saga@gmail.com wrote:

Feature #13743: Support linking of files opened with O_TMPFILE
https://bugs.ruby-lang.org/issues/13743

I like this feature.

patch.diff (2.44 KB)

+    if (!NIL_P(tmp) && from_fptr && from_fptr->fd >= 0) { /* when 'from' is an IO and opened */
+    char from_path[PATH_MAX];
+
+    rb_io_flush(from);
+    FilePathValue(to);
+    to = rb_str_encode_ospath(to);
+    snprintf(from_path, PATH_MAX,  "/proc/self/fd/%d", from_fptr->fd);

However, PATH_MAX (4096 on Linux) is excessive use of stack.
Since fd is an int, we can safely set a smaller size.

Also, I'm not sure why rb_io_flush needs to be called, here.

Thanks.

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

normalperson (Eric Wong) wrote:

However, PATH_MAX (4096 on Linux) is excessive use of stack.
Since fd is an int, we can safely set a smaller size.

static const char self_fd[] = "/proc/self/fd/%d";
char from_path[sizeof(self_fd) - 2 + DECIMAL_SIZE_OF_BITS(sizeof(int))];

Updated by akr (Akira Tanaka) over 1 year ago

I feel this is too Linux and environment specific.
For example, it depends /proc/fd.

I think that it is better to provide linkat(2) directly.
(Extend File.link or add File.linkat.)

Updated by matz (Yukihiro Matsumoto) over 1 year ago

  • Status changed from Open to Rejected

This API is pretty simple but only works on Linux. I am not positive to add platform-specific features to the language core. I'd rather recommend considering making it a gem.

Matz.

#6

Updated by Glass_saga (Masaki Matsushita) about 1 year ago

  • Related to Feature #4592: Tempfileを直接保存したい added
#7

Updated by Glass_saga (Masaki Matsushita) about 1 year ago

  • Related to deleted (Feature #4592: Tempfileを直接保存したい)

Also available in: Atom PDF