dir_size 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15ad8d180938c54cf324288340d1f866f9fc73ed
4
+ data.tar.gz: 822747bc1cf4e901e2d3e1a056fa0a286faa5dd9
5
+ SHA512:
6
+ metadata.gz: f6e71a06b911ec9d558f52456c1a745f41e9b3b78098c578a965618b0f17223315f361a15d974c0c757e7c2487f537ea27b585ba1d0638f8a68175453bba5981
7
+ data.tar.gz: 730bb7cc070eae20ebb86a9aab294046f4fbd8f2d9621484602c52d645a60d7464bc93af96820724cac12021937064d416ced2ca5c51e62edad57ba19cb63d6b
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.rake_tasks
data/.rake_tasks ADDED
@@ -0,0 +1,8 @@
1
+ build
2
+ clean
3
+ clobber
4
+ compile
5
+ compile:dir_size
6
+ install
7
+ install:local
8
+ release
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.2.3
6
+ before_install: gem install bundler -v 1.10.6
7
+ install:
8
+ - bundle install --jobs 8 --retry 8
9
+ before_script:
10
+ - bundle exec rake compile
11
+ script:
12
+ - bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://ruby.taobao.org'
2
+
3
+ # Specify your gem's dependencies in dir_size.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Bachue Zhou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # DirSize
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dir_size`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dir_size'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dir_size
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dir_size.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/extensiontask'
3
+
4
+ spec = Gem::Specification.load 'dir_size.gemspec'
5
+ Rake::ExtensionTask.new 'dir_size', spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dir_size"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/dir_size.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'dir_size'
7
+ spec.version = '0.1.0'
8
+ spec.date = Time.now.strftime('%Y-%m-%d')
9
+ spec.authors = ['Bachue Zhou']
10
+ spec.email = ['bachue.shu@gmail.com']
11
+
12
+ spec.summary = 'To calculate the directory size'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'http://gitcafe.com/bachue/dir_size'
15
+ spec.license = 'MIT'
16
+
17
+ spec.required_ruby_version = '>= 1.9.3'
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.require_paths = ['lib']
20
+ spec.extensions << 'ext/dir_size/extconf.rb'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake-compiler', '>= 0.9.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ end
@@ -0,0 +1,42 @@
1
+ #define _XOPEN_SOURCE 500
2
+ #include <ruby.h>
3
+ #include <stdlib.h>
4
+ #include <errno.h>
5
+ #include <ftw.h>
6
+ #include <limits.h>
7
+
8
+ VALUE rb_cDir;
9
+ void Init_dir_size(void);
10
+
11
+ static __thread unsigned long size = 0;
12
+
13
+ static int callback(const char *path, const struct stat *st, int typeflag, struct FTW *ftw) {
14
+ if (typeflag == FTW_F || typeflag == FTW_D || typeflag == FTW_SL || typeflag == FTW_SLN)
15
+ size += st->st_size;
16
+ return 0;
17
+ }
18
+
19
+ static int get_size(const char *path, unsigned long *psize) {
20
+ int ret;
21
+ size = 0;
22
+ ret = nftw(path, callback, 10, FTW_PHYS);
23
+ if (ret != -1) *psize = size;
24
+ return ret;
25
+ }
26
+
27
+ static VALUE rb_get_size(VALUE rb_self, VALUE rb_path) {
28
+ unsigned long lsize;
29
+ char path[PATH_MAX + 1];
30
+ Check_Type(rb_path, T_STRING);
31
+ strncpy(path, RSTRING_PTR(rb_path), RSTRING_LEN(rb_path));
32
+ path[RSTRING_LEN(rb_path)] = '\0';
33
+ if (get_size(path, &lsize) == -1)
34
+ rb_raise(rb_eRuntimeError, "Dir.size error: %s", strerror(errno));
35
+ else
36
+ return ULONG2NUM(lsize);
37
+ }
38
+
39
+ void Init_dir_size() {
40
+ rb_cDir = rb_const_get(rb_cObject, rb_intern("Dir"));
41
+ rb_define_singleton_method(rb_cDir, "size", rb_get_size, 1);
42
+ }
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+
3
+ extension_name = 'dir_size'
4
+ dir_config extension_name
5
+ create_makefile extension_name
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dir_size
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bachue Zhou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: To calculate the directory size
56
+ email:
57
+ - bachue.shu@gmail.com
58
+ executables: []
59
+ extensions:
60
+ - ext/dir_size/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rake_tasks"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - dir_size.gemspec
74
+ - ext/dir_size/dir_size.c
75
+ - ext/dir_size/extconf.rb
76
+ homepage: http://gitcafe.com/bachue/dir_size
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.9.3
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: To calculate the directory size
100
+ test_files: []
101
+ has_rdoc: