clonefile 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSES/BSD-3-Clause.txt +26 -0
- data/ext/clonefile/clonefile.c +52 -0
- data/ext/clonefile/extconf.rb +23 -0
- data/lib/clonefile.rb +27 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0bbe04002c44e0fe93d3b88c8cc914ef6cb6f4168a2bf8b3a25fb3f233e3e4c9
|
4
|
+
data.tar.gz: 13c886537a158e1fb4b44995bac5e8b2b9d5f498e8a8f955b12f8a888fbab7be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad10432424d32fc3a2419df7ad5f2818ef2e73a11d68d4963b2d894fd8027326a67366c003fdc0609e0fe7cd90de51d0581ed45d02c12e8283f1dc6c3962609d
|
7
|
+
data.tar.gz: b34234b63f61330c23ed4907a32301ce5ba30cace3cfd6529b58ca9817d7f01582a313fc1737b35d7ac67e5ff6b1c18bdd0f75592bf2f5ab3ada52b2f7bf7cc5
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright © 2020 Daniel Aleksandersen. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
4
|
+
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
|
+
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software without
|
15
|
+
specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
21
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
26
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// Copyright 2020 Daniel Aleksandersen <https://www.daniel.priv.no/>
|
2
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
#include "extconf.h"
|
6
|
+
|
7
|
+
VALUE rb_mod;
|
8
|
+
|
9
|
+
#ifdef __APPLE__
|
10
|
+
|
11
|
+
#include <sys/attr.h>
|
12
|
+
#include <sys/clonefile.h>
|
13
|
+
|
14
|
+
VALUE rb_clonefile(VALUE self, VALUE src, VALUE dest)
|
15
|
+
{
|
16
|
+
if (RB_TYPE_P(src, T_STRING) != 1 || RB_TYPE_P(dest, T_STRING) != 1)
|
17
|
+
{
|
18
|
+
rb_raise(rb_eTypeError, "Arguments must be path strings.");
|
19
|
+
}
|
20
|
+
|
21
|
+
if (clonefile(RSTRING_PTR(src), RSTRING_PTR(dest), 0) == 0)
|
22
|
+
{
|
23
|
+
return Qtrue;
|
24
|
+
}
|
25
|
+
|
26
|
+
return Qfalse;
|
27
|
+
}
|
28
|
+
|
29
|
+
void Init_clonefile()
|
30
|
+
{
|
31
|
+
rb_mod = rb_define_module("Clonefile");
|
32
|
+
|
33
|
+
rb_define_module_function(rb_mod, "darwin_clonefile", rb_clonefile, 2);
|
34
|
+
}
|
35
|
+
|
36
|
+
#endif
|
37
|
+
#ifdef __linux__
|
38
|
+
|
39
|
+
|
40
|
+
#include <sys/ioctl.h>
|
41
|
+
#include <linux/fs.h>
|
42
|
+
|
43
|
+
void Init_clonefile()
|
44
|
+
{
|
45
|
+
rb_mod = rb_define_module("Clonefile");
|
46
|
+
|
47
|
+
rb_define_const(rb_mod, "LINUX_IOCTL_FICLONE", INT2FIX(FICLONE));
|
48
|
+
rb_define_const(rb_mod, "LINUX_IOCTL_FICLONERANGE", INT2FIX(FICLONERANGE));
|
49
|
+
rb_define_const(rb_mod, "LINUX_IOCTL_FIDEDUPERANGE", INT2FIX(FIDEDUPERANGE));
|
50
|
+
}
|
51
|
+
|
52
|
+
#endif
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mkmf'
|
4
|
+
|
5
|
+
def dependency_header(header)
|
6
|
+
abort "Unmet dependency: #{header}" unless have_header(header)
|
7
|
+
end
|
8
|
+
|
9
|
+
if RUBY_PLATFORM =~ /darwin/
|
10
|
+
dependency_header('sys/attr.h')
|
11
|
+
dependency_header('sys/clonefile.h')
|
12
|
+
|
13
|
+
elsif RUBY_PLATFORM =~ /linux/
|
14
|
+
dependency_header('sys/ioctl.h')
|
15
|
+
dependency_header('linux/fs.h')
|
16
|
+
|
17
|
+
else
|
18
|
+
raise('Unsupported platform!')
|
19
|
+
end
|
20
|
+
|
21
|
+
create_header
|
22
|
+
|
23
|
+
create_makefile 'clonefile/clonefile'
|
data/lib/clonefile.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020 Daniel Aleksandersen <https://www.daniel.priv.no/>
|
4
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
5
|
+
|
6
|
+
# Clones files on copy-on-write file systems.
|
7
|
+
module Clonefile
|
8
|
+
# Clones src to dest path. Returns boolean. Raises exception if unsupported.
|
9
|
+
def self.always(src, dest)
|
10
|
+
if RUBY_PLATFORM =~ /darwin/
|
11
|
+
darwin_clonefile(src, dest)
|
12
|
+
elsif RUBY_PLATFORM =~ /linux/
|
13
|
+
src_fd = IO.sysopen(src, File::RDONLY | File::BINARY)
|
14
|
+
dest = File.new(dest, File::WRONLY | File::BINARY | File::CREAT)
|
15
|
+
dest.ioctl(LINUX_IOCTL_FICLONE, src_fd).zero?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Clones src to dest path. Falls back to a regular copy if unsupported.
|
20
|
+
def self.auto(src, dest)
|
21
|
+
always(src, dest)
|
22
|
+
rescue Errno::ENOTSUP, Errno::EXDEV
|
23
|
+
FileUtils.cp(src, dest)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'clonefile/clonefile'
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clonefile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Aleksandersen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Copy files using reflink/cloned extents on supported file systems. Supports
|
14
|
+
Linux and macOS.
|
15
|
+
email: code@daniel.priv.no
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/clonefile/extconf.rb
|
19
|
+
extra_rdoc_files:
|
20
|
+
- LICENSES/BSD-3-Clause.txt
|
21
|
+
files:
|
22
|
+
- LICENSES/BSD-3-Clause.txt
|
23
|
+
- ext/clonefile/clonefile.c
|
24
|
+
- ext/clonefile/extconf.rb
|
25
|
+
- lib/clonefile.rb
|
26
|
+
homepage:
|
27
|
+
licenses:
|
28
|
+
- BSD-3-Clause
|
29
|
+
metadata:
|
30
|
+
bug_tracker_uri: https://codeberg.org/da/ruby-clonefile/issues
|
31
|
+
source_code_uri: https://codeberg.org/da/ruby-clonefile
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements:
|
47
|
+
- Linux 4.9.1+ or macOS 10.12.1.
|
48
|
+
- " A copy-on-write file system."
|
49
|
+
rubygems_version: 3.1.2
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Clone files on copy-on-write file systems.
|
53
|
+
test_files: []
|