summaryrefslogtreecommitdiffstats
path: root/src/web/server/h2o/libh2o/deps/mruby-dir/mrblib/dir.rb
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:18 +0000
commit5da14042f70711ea5cf66e034699730335462f66 (patch)
tree0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/web/server/h2o/libh2o/deps/mruby-dir/mrblib/dir.rb
parentReleasing debian version 1.44.3-2. (diff)
downloadnetdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz
netdata-5da14042f70711ea5cf66e034699730335462f66.zip
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/web/server/h2o/libh2o/deps/mruby-dir/mrblib/dir.rb')
-rw-r--r--src/web/server/h2o/libh2o/deps/mruby-dir/mrblib/dir.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/web/server/h2o/libh2o/deps/mruby-dir/mrblib/dir.rb b/src/web/server/h2o/libh2o/deps/mruby-dir/mrblib/dir.rb
new file mode 100644
index 000000000..065ca1c22
--- /dev/null
+++ b/src/web/server/h2o/libh2o/deps/mruby-dir/mrblib/dir.rb
@@ -0,0 +1,64 @@
+class Dir
+ def each(&block)
+ while s = self.read
+ block.call(s)
+ end
+ self
+ end
+
+ alias pos tell
+ alias pos= seek
+
+ def self.entries(path)
+ a = []
+ self.open(path) { |d|
+ while s = d.read
+ a << s
+ end
+ }
+ a
+ end
+
+ def self.foreach(path, &block)
+ if block
+ self.open(path).each { |f| block.call(f) }
+ else
+ self.open(path).each
+ end
+ end
+
+ def self.open(path, &block)
+ if block
+ d = self.new(path)
+ begin
+ block.call(d)
+ ensure
+ d.close
+ end
+ else
+ self.new(path)
+ end
+ end
+
+ def self.chdir(path, &block)
+ my = self # workaround for https://github.com/mruby/mruby/issues/1579
+ if block
+ wd = self.getwd
+ begin
+ self._chdir(path)
+ block.call(path)
+ ensure
+ my._chdir(wd)
+ end
+ else
+ self._chdir(path)
+ end
+ end
+
+ class << self
+ alias exists? exist?
+ alias pwd getwd
+ alias rmdir delete
+ alias unlink delete
+ end
+end