Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ d1474affa8e105bece209cc9d594bb0a989859e1
2da92388b948821269b18d6b178a680f17e41750
5062c0c621d887367af8a054e5e5d83d7ec57dd3

# Indentation
0e4bad888e605d424b9222ae0ca43f85c1634e5e

# Enable Style/StringLiterals cop for RubyGems/Bundler
d7ffd3fea402239b16833cc434404a7af82d44f3

Expand Down
140 changes: 96 additions & 44 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,16 +506,16 @@ fnmatch(
VALUE rb_cDir;
static VALUE sym_directory, sym_link, sym_file, sym_unknown;

#ifdef DT_BLK
#if defined(DT_BLK) || defined(S_IFBLK)
static VALUE sym_block_device;
#endif
#ifdef DT_CHR
#if defined(DT_CHR) || defined(S_IFCHR)
static VALUE sym_character_device;
#endif
#ifdef DT_FIFO
#if defined(DT_FIFO) || defined(S_IFIFO)
static VALUE sym_fifo;
#endif
#ifdef DT_SOCK
#if defined(DT_SOCK) || defined(S_IFSOCK)
static VALUE sym_socket;
#endif

Expand Down Expand Up @@ -919,53 +919,101 @@ dir_read(VALUE dir)
}
}

static VALUE dir_each_entry(VALUE, VALUE (*)(VALUE, VALUE, unsigned char), VALUE, int);
struct dir_entry_args {
struct dir_data *dirp;
struct dirent *dp;
};

static VALUE dir_each_entry(VALUE, VALUE (*)(VALUE, VALUE, struct dir_entry_args *), VALUE, int);

static VALUE
dir_yield(VALUE arg, VALUE path, unsigned char dtype)
dir_yield(VALUE arg, VALUE path, struct dir_entry_args *_unused)
{
return rb_yield(path);
}

static int do_lstat(int fd, const char *path, struct stat *pst, int flags, rb_encoding *enc);

static VALUE
dir_yield_with_type(VALUE arg, VALUE path, unsigned char dtype)
dir_yield_with_type(VALUE arg, VALUE path, struct dir_entry_args *dir_entry)
{
VALUE type;
switch (dtype) {
switch (dir_entry->dp->d_type) {
#ifdef DT_BLK
case DT_BLK:
type = sym_block_device;
break;
case DT_BLK:
type = sym_block_device;
break;
#endif
#ifdef DT_CHR
case DT_CHR:
type = sym_character_device;
break;
case DT_CHR:
type = sym_character_device;
break;
#endif
case DT_DIR:
type = sym_directory;
break;
case DT_DIR:
type = sym_directory;
break;
#ifdef DT_FIFO
case DT_FIFO:
type = sym_fifo;
break;
case DT_FIFO:
type = sym_fifo;
break;
#endif
case DT_LNK:
type = sym_link;
break;
case DT_REG:
type = sym_file;
break;
case DT_LNK:
type = sym_link;
break;
case DT_REG:
type = sym_file;
break;
#ifdef DT_SOCK
case DT_SOCK:
type = sym_socket;
break;
case DT_SOCK:
type = sym_socket;
break;
#endif
default:
type = sym_unknown;
break;
default:
type = sym_unknown;
break;
}

#ifdef HAVE_DIRFD
if (RUBY_DEBUG || RB_UNLIKELY(type == sym_unknown)) {
struct stat st;
if (do_lstat(dirfd(dir_entry->dirp->dir), dir_entry->dp->d_name, &st, 0, rb_filesystem_encoding()) == 0) {
switch (st.st_mode & S_IFMT) {
case S_IFDIR:
type = sym_directory;
break;
case S_IFLNK:
type = sym_link;
break;
case S_IFREG:
type = sym_file;
break;
#ifdef S_IFSOCK
case S_IFSOCK:
type = sym_socket;
break;
#endif
#ifdef S_IFIFO
case S_IFIFO:
type = sym_fifo;
break;
#endif
#ifdef S_IFBLK
case S_IFBLK:
type = sym_block_device;
break;
#endif
#ifdef S_IFCHR
case S_IFCHR:
type = sym_character_device;
break;
#endif
default:
break;
}
}
}
#endif // HAVE_DIRFD

if (NIL_P(arg)) {
return rb_yield_values(2, path, type);
}
Expand Down Expand Up @@ -1001,7 +1049,7 @@ dir_each(VALUE dir)
}

static VALUE
dir_each_entry(VALUE dir, VALUE (*each)(VALUE, VALUE, unsigned char), VALUE arg, int children_only)
dir_each_entry(VALUE dir, VALUE (*each)(VALUE, VALUE, struct dir_entry_args *), VALUE arg, int children_only)
{
struct dir_data *dirp;
struct dirent *dp;
Expand All @@ -1027,7 +1075,11 @@ dir_each_entry(VALUE dir, VALUE (*each)(VALUE, VALUE, unsigned char), VALUE arg,
else
#endif
path = rb_external_str_new_with_enc(name, namlen, dirp->enc);
(*each)(arg, path, dp->d_type);
struct dir_entry_args each_args = {
.dirp = dirp,
.dp = dp,
};
(*each)(arg, path, &each_args);
}
return dir;
}
Expand Down Expand Up @@ -1865,7 +1917,7 @@ nogvl_stat(void *args)

/* System call with warning */
static int
do_stat(int fd, size_t baselen, const char *path, struct stat *pst, int flags, rb_encoding *enc)
do_stat(int fd, const char *path, struct stat *pst, int flags, rb_encoding *enc)
{
#if USE_OPENDIR_AT
struct fstatat_args args;
Expand Down Expand Up @@ -1897,7 +1949,7 @@ nogvl_lstat(void *args)
#endif

static int
do_lstat(int fd, size_t baselen, const char *path, struct stat *pst, int flags, rb_encoding *enc)
do_lstat(int fd, const char *path, struct stat *pst, int flags, rb_encoding *enc)
{
#if USE_OPENDIR_AT
struct fstatat_args args;
Expand Down Expand Up @@ -2840,15 +2892,15 @@ glob_helper(

if (*path) {
if (match_all && pathtype == path_unknown) {
if (do_lstat(fd, baselen, path, &st, flags, enc) == 0) {
if (do_lstat(fd, path, &st, flags, enc) == 0) {
pathtype = IFTODT(st.st_mode);
}
else {
pathtype = path_noent;
}
}
if (match_dir && (pathtype == path_unknown || pathtype == path_symlink)) {
if (do_stat(fd, baselen, path, &st, flags, enc) == 0) {
if (do_stat(fd, path, &st, flags, enc) == 0) {
pathtype = IFTODT(st.st_mode);
}
else {
Expand Down Expand Up @@ -2976,7 +3028,7 @@ glob_helper(
if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1) &&
new_pathtype == path_unknown) {
/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
if (do_lstat(fd, baselen, buf, &st, flags, enc) == 0)
if (do_lstat(fd, buf, &st, flags, enc) == 0)
new_pathtype = IFTODT(st.st_mode);
else
new_pathtype = path_noent;
Expand Down Expand Up @@ -3532,7 +3584,7 @@ dir_foreach(int argc, VALUE *argv, VALUE io)
}

static VALUE
dir_entry_ary_push(VALUE ary, VALUE entry, unsigned char ftype)
dir_entry_ary_push(VALUE ary, VALUE entry, struct dir_entry_args *_unused)
{
return rb_ary_push(ary, entry);
}
Expand Down Expand Up @@ -3935,16 +3987,16 @@ Init_Dir(void)
sym_file = ID2SYM(rb_intern("file"));
sym_unknown = ID2SYM(rb_intern("unknown"));

#ifdef DT_BLK
#if defined(DT_BLK) || defined(S_IFBLK)
sym_block_device = ID2SYM(rb_intern("blockSpecial"));
#endif
#ifdef DT_CHR
#if defined(DT_CHR) || defined(S_IFCHR)
sym_character_device = ID2SYM(rb_intern("characterSpecial"));
#endif
#ifdef DT_FIFO
#if defined(DT_FIFO) || defined(S_IFIFO)
sym_fifo = ID2SYM(rb_intern("fifo"));
#endif
#ifdef DT_SOCK
#if defined(DT_SOCK) || defined(S_IFSOCK)
sym_socket = ID2SYM(rb_intern("socket"));
#endif

Expand Down
12 changes: 0 additions & 12 deletions doc/maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,12 @@ It may needs to make consensus on ruby-core/ruby-dev before making major changes
* https://github.com/ruby/rss
* https://rubygems.org/gems/rss

### net-ftp

* Shugo Maeda ([shugo])
* https://github.com/ruby/net-ftp
* https://rubygems.org/gems/net-ftp

### net-imap

* Nicholas A. Evans ([nevans])
* https://github.com/ruby/net-imap
* https://rubygems.org/gems/net-imap

### net-pop

* https://github.com/ruby/net-pop
* https://rubygems.org/gems/net-pop

### net-smtp

* TOMITA Masahiro ([tmtm])
Expand Down Expand Up @@ -711,7 +700,6 @@ It may needs to make consensus on ruby-core/ruby-dev before making major changes
[k-tsj]: https://github.com/k-tsj
[nevans]: https://github.com/nevans
[tmtm]: https://github.com/tmtm
[shugo]: https://github.com/shugo
[soutaro]: https://github.com/soutaro
[yui-knk]: https://github.com/yui-knk
[hasumikin]: https://github.com/hasumikin
Expand Down
4 changes: 0 additions & 4 deletions doc/standard_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ of each.
- [test-unit]: A compatibility layer for MiniTest
- [rexml][rexml-doc] ([GitHub][rexml]): An XML toolkit for Ruby
- [rss]: A family of libraries supporting various XML-based "feeds"
- [net-ftp]: Support for the File Transfer Protocol
- [net-imap]: Ruby client API for the Internet Message Access Protocol
- [net-pop]: Ruby client library for POP3
- [net-smtp]: Simple Mail Transfer Protocol client library for Ruby
- [matrix]: Represents a mathematical matrix
- [prime]: Prime numbers and factorization library
Expand Down Expand Up @@ -164,10 +162,8 @@ of each.
[matrix]: https://github.com/ruby/matrix
[minitest]: https://github.com/seattlerb/minitest
[mutex_m]: https://github.com/ruby/mutex_m
[net-ftp]: https://github.com/ruby/net-ftp
[net-http]: https://github.com/ruby/net-http
[net-imap]: https://github.com/ruby/net-imap
[net-pop]: https://github.com/ruby/net-pop
[net-smtp]: https://github.com/ruby/net-smtp
[nkf]: https://github.com/ruby/nkf
[observer]: https://github.com/ruby/observer
Expand Down
2 changes: 1 addition & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2412,7 +2412,7 @@ rb_file_ftype(mode_t mode)
t = "unknown";
}

return rb_usascii_str_new2(t);
return rb_fstring_cstr(t);
}

/*
Expand Down
2 changes: 0 additions & 2 deletions gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ rake 13.3.1 https://github.com/ruby/rake
test-unit 3.7.7 https://github.com/test-unit/test-unit
rexml 3.4.4 https://github.com/ruby/rexml
rss 0.3.2 https://github.com/ruby/rss
net-ftp 0.3.9 https://github.com/ruby/net-ftp
net-imap 0.6.2 https://github.com/ruby/net-imap d9ae35ef913a45f83387b8444cdce4fb1cbf01af
net-pop 0.1.2 https://github.com/ruby/net-pop
net-smtp 0.5.1 https://github.com/ruby/net-smtp
matrix 0.4.3 https://github.com/ruby/matrix
prime 0.1.4 https://github.com/ruby/prime
Expand Down
4 changes: 3 additions & 1 deletion lib/rubygems/remote_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def fetch_http(uri, last_modified = nil, head = false, depth = 0)

fetch_http(location, last_modified, head, depth + 1)
else
raise FetchError.new("bad response #{response.message} #{response.code}", uri)
custom_error = response["X-Error-Message"]
error_detail = custom_error || response.message
raise FetchError.new("Bad response #{error_detail} #{response.code}", uri)
end
end

Expand Down
11 changes: 7 additions & 4 deletions spec/ruby/library/net-ftp/FTPError_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require_relative '../../spec_helper'
require 'net/ftp'

describe "Net::FTPError" do
it "is an Exception" do
Net::FTPError.should < Exception
ruby_version_is ""..."4.1" do
require 'net/ftp'

describe "Net::FTPError" do
it "is an Exception" do
Net::FTPError.should < Exception
end
end
end
17 changes: 10 additions & 7 deletions spec/ruby/library/net-ftp/FTPPermError_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
require_relative '../../spec_helper'
require 'net/ftp'

describe "Net::FTPPermError" do
it "is an Exception" do
Net::FTPPermError.should < Exception
end
ruby_version_is ""..."4.1" do
require 'net/ftp'

describe "Net::FTPPermError" do
it "is an Exception" do
Net::FTPPermError.should < Exception
end

it "is a subclass of Net::FTPError" do
Net::FTPPermError.should < Net::FTPError
it "is a subclass of Net::FTPError" do
Net::FTPPermError.should < Net::FTPError
end
end
end
Loading