Skip to content

Commit

Permalink
Rename File.real_path to .realpath (crystal-lang#12552)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and lbguilherme committed Oct 24, 2022
1 parent 423ab3e commit a54f327
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/crystal/system/unix/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ module Crystal::System::File
end
end

def self.real_path(path)
real_path_ptr = LibC.realpath(path, nil)
raise ::File::Error.from_errno("Error resolving real path", file: path) unless real_path_ptr
String.new(real_path_ptr).tap { LibC.free(real_path_ptr.as(Void*)) }
def self.realpath(path)
realpath_ptr = LibC.realpath(path, nil)
raise ::File::Error.from_errno("Error resolving real path", file: path) unless realpath_ptr
String.new(realpath_ptr).tap { LibC.free(realpath_ptr.as(Void*)) }
end

def self.link(old_path, new_path)
Expand Down
4 changes: 2 additions & 2 deletions src/crystal/system/wasi/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module Crystal::System::File
raise NotImplementedError.new "Crystal::System::File.chown"
end

def self.real_path(path)
raise NotImplementedError.new "Crystal::System::File.real_path"
def self.realpath(path)
raise NotImplementedError.new "Crystal::System::File.realpath"
end

def self.utime(atime : ::Time, mtime : ::Time, filename : String) : Nil
Expand Down
8 changes: 4 additions & 4 deletions src/crystal/system/win32/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ module Crystal::System::File
end
end

def self.real_path(path : String) : String
def self.realpath(path : String) : String
# TODO: read links using https://msdn.microsoft.com/en-us/library/windows/desktop/aa364571(v=vs.85).aspx
win_path = to_windows_path(path)

real_path = System.retry_wstr_buffer do |buffer, small_buf|
realpath = System.retry_wstr_buffer do |buffer, small_buf|
len = LibC.GetFullPathNameW(win_path, buffer.size, buffer, nil)
if 0 < len < buffer.size
break String.from_utf16(buffer[0, len])
Expand All @@ -192,11 +192,11 @@ module Crystal::System::File
end
end

unless exists? real_path
unless exists? realpath
raise ::File::Error.from_os_error("Error resolving real path", Errno::ENOENT, file: path)
end

real_path
realpath
end

def self.link(old_path : String, new_path : String) : Nil
Expand Down
4 changes: 2 additions & 2 deletions src/exception/call_stack/mach_o.cr
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ struct Exception::CallStack
end
end

program = File.real_path(String.new(buffer))
program = File.realpath(String.new(buffer))

LibC._dyld_image_count.times do |i|
if program == File.real_path(String.new(LibC._dyld_get_image_name(i)))
if program == File.realpath(String.new(LibC._dyld_get_image_name(i)))
return LibC._dyld_get_image_vmaddr_slide(i)
end
end
Expand Down
8 changes: 7 additions & 1 deletion src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,14 @@ class File < IO::FileDescriptor
end

# Resolves the real path of *path* by following symbolic links.
def self.realpath(path : Path | String) : String
Crystal::System::File.realpath(path.to_s)
end

# :ditto:
@[Deprecated("Use `.realpath` instead.")]
def self.real_path(path : Path | String) : String
Crystal::System::File.real_path(path.to_s)
realpath(path)
end

# Creates a new link (also known as a hard link) at *new_path* to an existing file
Expand Down
2 changes: 1 addition & 1 deletion src/process/executable_path.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Process
def self.executable_path : String?
if executable = executable_path_impl
begin
File.real_path(executable)
File.realpath(executable)
rescue File::Error
end
end
Expand Down

0 comments on commit a54f327

Please sign in to comment.