mkdtemp 1.1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
data/ext/depend CHANGED
@@ -1,18 +1,25 @@
1
- # depend
2
- # Additional material for Makefile
3
- # Copyright 2008-2009 Wincent Colaiuta
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
1
+ # Copyright 2008-2010 Wincent Colaiuta. All rights reserved.
8
2
  #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
13
5
  #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
+ # 1. Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ #
12
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ # POSSIBILITY OF SUCH DAMAGE.
16
23
 
17
24
  # don't warn about unused params because many Ruby methods accept "self" but don't use it
18
25
  CFLAGS += -std=gnu99 -Wall -Wextra -Wno-unused-parameter
@@ -1,17 +1,25 @@
1
- # Copyright 2007 Wincent Colaiuta
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
1
+ # Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
6
2
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
+ # 1. Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ #
12
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ # POSSIBILITY OF SUCH DAMAGE.
14
23
 
15
24
  require 'mkmf'
16
25
  create_makefile('mkdtemp')
17
-
@@ -1,70 +1,110 @@
1
- /*
2
- Copyright 2007-2009 Wincent Colaiuta
3
- This program is free software: you can redistribute it and/or modify
4
- it under the terms of the GNU General Public License as published by
5
- the Free Software Foundation, either version 3 of the License, or
6
- (at your option) any later version.
7
-
8
- This program is distributed in the hope that it will be useful,
9
- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- GNU General Public License for more details.
12
-
13
- You should have received a copy of the GNU General Public License
14
- along with this program. If not, see <http://www.gnu.org/licenses/>.
15
- */
1
+ // Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice,
7
+ // this list of conditions and the following disclaimer.
8
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ // this list of conditions and the following disclaimer in the documentation
10
+ // and/or other materials provided with the distribution.
11
+ //
12
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16
+ // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17
+ // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18
+ // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20
+ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ // POSSIBILITY OF SUCH DAMAGE.
16
23
 
17
24
  #include <ruby.h>
18
25
  #include <errno.h>
19
26
  #include <unistd.h>
20
27
  #include "ruby_compat.h"
21
28
 
22
- /*
23
-
24
- call-seq:
25
- Dir.mkdtemp([string]) -> String or nil
26
-
27
- This method securely creates temporary directories. It is a wrapper for the mkdtemp() function in the standard C library. It takes
28
- an optional String parameter as a template describing the desired form of the directory name and overwriting the template in-place;
29
- if no template is supplied then "/tmp/temp.XXXXXX" is used as a default.
29
+ // helper function needed by rb_iterate; see:
30
+ // http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/144100
31
+ VALUE call_chdir(VALUE dir)
32
+ {
33
+ return rb_funcall(rb_cDir, rb_intern("chdir"), 1, dir);
34
+ }
30
35
 
31
- Note that the exact implementation of mkdtemp() may vary depending on the target system. For example, on Mac OS X at the time of
32
- writing, the man page states that the template may contain "some number" of "Xs" on the end of the string, whereas on Red Hat
33
- Enterprise Linux it states that the template suffix "must be XXXXXX".
36
+ // helper function needed by rb_iterate
37
+ VALUE yield_block(VALUE ignored, VALUE block)
38
+ {
39
+ return rb_funcall(block, rb_intern("call"), 0);
40
+ }
34
41
 
35
- */
42
+ // Document-method: mkdtemp
43
+ //
44
+ // call-seq:
45
+ // Dir.mkdtemp([string]) -> String or nil
46
+ // Dir.mkdtemp([string]) { ... } -> String or nil
47
+ //
48
+ // This method securely creates temporary directories. It is a wrapper for the
49
+ // mkdtemp() function in the standard C library. It takes an optional String
50
+ // parameter as a template describing the desired form of the directory name
51
+ // and overwriting the template in-place; if no template is supplied then
52
+ // "/tmp/temp.XXXXXX" is used as a default.
53
+ //
54
+ // If supplied a block, performs a Dir.chdir into the created directory and
55
+ // yields to the block:
56
+ //
57
+ // # this: # is a shorthand for:
58
+ // Dir.mkdtemp do # dir = Dir.mkdtemp
59
+ // puts Dir.pwd # Dir.chdir dir do
60
+ // end # puts Dir.pwd
61
+ // # end
62
+ //
63
+ // Note that the exact implementation of mkdtemp() may vary depending on the
64
+ // target system. For example, on Mac OS X at the time of writing, the man page
65
+ // states that the template may contain "some number" of "Xs" on the end of the
66
+ // string, whereas on Red Hat Enterprise Linux it states that the template
67
+ // suffix "must be XXXXXX".
36
68
  static VALUE dir_mkdtemp_m(int argc, VALUE *argv, VALUE self)
37
69
  {
38
- VALUE template;
70
+ VALUE template, block;
39
71
  char *c_template;
40
72
  char *path;
41
73
 
42
- /* process argument */
43
- if (rb_scan_args(argc, argv, "01", &template) == 0) /* check for 0 mandatory arguments, 1 optional argument */
44
- template = Qnil; /* default to nil if no argument passed */
74
+ // process arguments
75
+ if (rb_scan_args(argc, argv, "01&", &template, &block) == 0) // 0 mandatory, 1 optional, 1 block
76
+ template = Qnil; // default to nil if no argument passed
45
77
  if (NIL_P(template))
46
- template = rb_str_new2("/tmp/temp.XXXXXX"); /* fallback to this template if passed nil */
47
- SafeStringValue(template); /* raises if template is tainted and SAFE level > 0 */
48
- template = StringValue(template); /* duck typing support */
78
+ template = rb_str_new2("/tmp/temp.XXXXXX"); // fallback to this template if passed nil
79
+ SafeStringValue(template); // raises if template is tainted and SAFE level > 0
80
+ template = StringValue(template); // duck typing support
49
81
 
50
- /* create temporary storage */
82
+ // create temporary storage
51
83
  c_template = malloc(RSTRING_LEN(template) + 1);
52
84
  if (!c_template)
53
85
  rb_raise(rb_eNoMemError, "failed to allocate %ld bytes of template storage", RSTRING_LEN(template) + 1);
54
86
  strncpy(c_template, RSTRING_PTR(template), RSTRING_LEN(template));
55
- c_template[RSTRING_LEN(template)] = 0; /* NUL-terminate */
87
+ c_template[RSTRING_LEN(template)] = 0; // NUL-terminate
56
88
 
57
- /* fill out template */
89
+ // fill out template
58
90
  path = mkdtemp(c_template);
59
91
  if (path)
60
92
  template = rb_str_new2(path);
61
93
  free(c_template);
62
94
  if (path == NULL)
63
95
  rb_raise(rb_eSystemCallError, "mkdtemp failed (error #%d: %s)", errno, strerror(errno));
96
+
97
+ // yield to block if given, inside Dir.chdir
98
+ if (rb_block_given_p() == Qtrue)
99
+ rb_iterate(call_chdir, template, yield_block, block);
64
100
  return template;
65
101
  }
66
102
 
67
103
  void Init_mkdtemp()
68
104
  {
69
- rb_define_module_function(rb_cDir, "mkdtemp", dir_mkdtemp_m, -1);
105
+ #if 0
106
+ // for Yardoc, need to fake this here
107
+ VALUE rb_cDir = rb_define_class("Dir", rb_cObject);
108
+ #endif
109
+ rb_define_singleton_method(rb_cDir, "mkdtemp", dir_mkdtemp_m, -1);
70
110
  }
@@ -1,19 +1,28 @@
1
- # Copyright 2008-2009 Wincent Colaiuta
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
1
+ # Copyright 2008-2010 Wincent Colaiuta. All rights reserved.
6
2
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
+ # 1. Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ #
12
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ # POSSIBILITY OF SUCH DAMAGE.
14
23
 
15
24
  class Dir
16
25
  module Mkdtemp
17
- VERSION = '1.1.1'
26
+ VERSION = '1.2'
18
27
  end # module Mkdtemp
19
28
  end # class Dir
metadata CHANGED
@@ -1,7 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkdtemp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 2
8
+ version: "1.2"
5
9
  platform: ruby
6
10
  authors:
7
11
  - Wincent Colaiuta
@@ -9,10 +13,24 @@ autorequire:
9
13
  bindir: bin
10
14
  cert_chain: []
11
15
 
12
- date: 2009-12-06 00:00:00 +01:00
16
+ date: 2010-07-29 00:00:00 +02:00
13
17
  default_executable:
14
- dependencies: []
15
-
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rspec
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 2
28
+ - 0
29
+ - 0
30
+ - beta
31
+ version: 2.0.0.beta
32
+ type: :development
33
+ version_requirements: *id001
16
34
  description: " mkdtemp is a C extension that wraps the Standard C Library function\n of the same name to make secure creation of temporary directories\n easily available from within Ruby.\n"
17
35
  email: win@wincent.com
18
36
  executables: []
@@ -23,14 +41,12 @@ extra_rdoc_files: []
23
41
 
24
42
  files:
25
43
  - lib/mkdtemp/version.rb
26
- - spec/mkdtemp_spec.rb
27
- - spec/spec_helper.rb
28
44
  - ext/mkdtemp.c
29
45
  - ext/ruby_compat.h
30
46
  - ext/extconf.rb
31
47
  - ext/depend
32
- has_rdoc: true
33
- homepage: http://mkdtemp.rubyforge.org/
48
+ has_rdoc: false
49
+ homepage: https://wincent.com/products/mkdtemp
34
50
  licenses: []
35
51
 
36
52
  post_install_message:
@@ -43,18 +59,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
59
  requirements:
44
60
  - - ">="
45
61
  - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
46
64
  version: "0"
47
- version:
48
65
  required_rubygems_version: !ruby/object:Gem::Requirement
49
66
  requirements:
50
67
  - - ">="
51
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
52
71
  version: "0"
53
- version:
54
72
  requirements: []
55
73
 
56
74
  rubyforge_project: mkdtemp
57
- rubygems_version: 1.3.5
75
+ rubygems_version: 1.3.6
58
76
  signing_key:
59
77
  specification_version: 3
60
78
  summary: Secure creation of temporary directories
@@ -1,78 +0,0 @@
1
- # Copyright 2008 Wincent Colaiuta
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
6
- #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
-
15
- require File.join(File.dirname(__FILE__), 'spec_helper')
16
-
17
- describe 'Dir.mkdtemp' do
18
- before do
19
- if not File.exist? '/tmp'
20
- pending "cannot run spec because '/tmp' does not exist"
21
- elsif not File.directory? '/tmp'
22
- pending "cannot run spec because '/tmp' is not a directory"
23
- elsif not File.writable? '/tmp'
24
- pending "cannot run spec because '/tmp' is not writeable"
25
- end
26
- end
27
-
28
- it 'should return the modified template path' do
29
- path = Dir.mkdtemp
30
- path.should be_kind_of(String)
31
- path.should_not == '/tmp/temp.XXXXXX'
32
- end
33
-
34
- it 'should create the directory corresponding to the template' do
35
- path = Dir.mkdtemp
36
- File.exist?(path).should == true
37
- File.directory?(path).should == true
38
- end
39
-
40
- it 'should create the directory with write permissions' do
41
- path = Dir.mkdtemp
42
- File.writable?(path).should == true
43
- end
44
-
45
- it 'should create the directory with read permissions' do
46
- path = Dir.mkdtemp
47
- File.readable?(path).should == true
48
- end
49
-
50
- it 'should create the directory with secure ownership (same user as caller)' do
51
- path = Dir.mkdtemp
52
- File.owned?(path).should == true
53
- end
54
-
55
- it 'should complain if passed a template that includes non-existentent parent directories' do
56
- non_existent_dir = '/temp-which-does-not-exist'
57
- if File.exist? non_existent_dir
58
- pending "cannot run because '#{non_existent_dir}' exists"
59
- end
60
- lambda { Dir.mkdtemp "/#{non_existent_dir}/temp.XXXXXX" }.should raise_error(SystemCallError)
61
- end
62
-
63
- it 'should use "/tmp/temp.XXXXXX" as a template if passed nil' do
64
- path = Dir.mkdtemp
65
- path.should match(%r{\A/tmp/temp\..{6}\z})
66
- path.should_not == '/tmp/temp.XXXXXX'
67
- end
68
-
69
- it 'should use substitute random characters for the trailing "Xs" in the template' do
70
- path = Dir.mkdtemp '/tmp/test.XXXXXX'
71
- path.should_not == '/tmp/test.XXXXXX'
72
- end
73
-
74
- it 'should leave the prefix portion of the template unchanged' do
75
- path = Dir.mkdtemp '/tmp/test.XXXXXX'
76
- path.should match(%r{\A/tmp/test\..{6}\z})
77
- end
78
- end
@@ -1,18 +0,0 @@
1
- # Copyright 2008 Wincent Colaiuta
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
6
- #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
-
15
- require 'pathname'
16
- require 'rubygems'
17
- require 'spec'
18
- require File.join(File.dirname(__FILE__), '..', 'ext', 'mkdtemp')