swhid 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab5130c9128fd1942d8a4a01eecb6d5f403f38fc2ce53d72323b08350e30bdf4
4
- data.tar.gz: a7c5c116fcd54c08f7d51b4125d4871f25b98aacc4f7ab818ebae670fc0972c9
3
+ metadata.gz: ee71514f26b0e91e02344d741fdfb56dc4aa5d9314e30dcc3c5d85caa68f8973
4
+ data.tar.gz: 4f087cd83b505e88543e991aa24d8fb88368596e4b108128de52d562e2d81025
5
5
  SHA512:
6
- metadata.gz: ad64d5ffad60fde8ec7399abcd63af7c34ae203c54f469df9866283864f1850c0f9b1c112ab89300c7ea52f56d5809189bbe6ec0bd2c9fc2ed85510daa3b2d37
7
- data.tar.gz: a44ef79ecd7a5d64f4d29c56f470b749ab61eac0d3f3ddd29c8b4798f334fa3f43222b8b463819f221e5687ca1355f7c23b7754be43a739009aafa4adba3e3cd
6
+ metadata.gz: a94007e0ee145b967ec7f2ac0007dcf996207990bec1af8ce3a63fc4f0ddd0e4a59afe6bf1385a4e0f9b9b033a3f0301657835751e653b1f1ed5fb457a3a6b90
7
+ data.tar.gz: 0f8a27c61f50d91519564fe4f7a6483b23415c600ffc6d49df26141388faf71ab547aa06e56450a6df9d95b91d6560c3c773a65c80682e6d87d5538858fd5e68
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2026-01-12
4
+
5
+ ### Added
6
+ - Windows support for directory SWHID computation
7
+ - File permissions read from Git index on Windows where filesystem permissions unavailable
8
+ - Optional `permissions:` parameter for `FromFilesystem.from_directory_path` to pass explicit file modes
9
+ - CI testing on Windows (Ruby 3.4 and 4.0)
10
+
11
+ ### Changed
12
+ - Archive extraction in tests now uses pure Ruby (Zlib/TarReader/Zip) instead of shell commands
13
+
3
14
  ## [0.3.1] - 2025-11-23
4
15
 
5
16
  ### Fixed
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andrew Nesbitt
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -261,6 +261,36 @@ SWHIDs can include optional qualifiers to provide context:
261
261
 
262
262
  The hash computation for content, directory, revision, and release objects is compatible with Git's object hashing. This means you can use this gem to compute the same hashes that Git would produce for the same objects.
263
263
 
264
+ ## Windows Support
265
+
266
+ The library works on Windows with some considerations for file permissions.
267
+
268
+ Directory SWHIDs include file permission bits (executable vs non-executable). Windows doesn't store Unix-style permissions, so the library uses these strategies:
269
+
270
+ 1. **Files in a Git repository**: Permissions are read from the Git index, which works correctly on all platforms.
271
+
272
+ 2. **Extracted archives**: When extracting tar.gz files, pass the permissions from tar headers:
273
+
274
+ ```ruby
275
+ require 'zlib'
276
+ require 'rubygems/package'
277
+
278
+ permissions = {}
279
+ Zlib::GzipReader.open(tarball) do |gz|
280
+ Gem::Package::TarReader.new(gz) do |tar|
281
+ tar.each do |entry|
282
+ next unless entry.file?
283
+ File.binwrite(dest_path, entry.read)
284
+ permissions[dest_path] = entry.header.mode
285
+ end
286
+ end
287
+ end
288
+
289
+ swhid = Swhid::FromFilesystem.from_directory_path(extract_dir, permissions: permissions)
290
+ ```
291
+
292
+ 3. **Other directories**: Without Git or explicit permissions, Windows will treat all files as non-executable. If the directory contains executable files, the hash will differ from Linux/macOS.
293
+
264
294
  ## Development
265
295
 
266
296
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -274,3 +304,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/andrew
274
304
  ## Code of Conduct
275
305
 
276
306
  Everyone interacting in the Swhid project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/andrew/swhid/blob/main/CODE_OF_CONDUCT.md).
307
+
308
+ ## License
309
+
310
+ [MIT](LICENSE)
@@ -5,15 +5,23 @@ require "find"
5
5
 
6
6
  module Swhid
7
7
  module FromFilesystem
8
- def self.from_directory_path(path)
8
+ def self.from_directory_path(path, git_repo: nil, permissions: nil)
9
9
  raise ArgumentError, "Path does not exist: #{path}" unless File.exist?(path)
10
10
  raise ArgumentError, "Path is not a directory: #{path}" unless File.directory?(path)
11
11
 
12
- entries = build_entries(path)
12
+ git_repo ||= discover_git_repo(path)
13
+ entries = build_entries(path, git_repo: git_repo, permissions: permissions)
13
14
  Swhid.from_directory(entries)
14
15
  end
15
16
 
16
- def self.build_entries(dir_path)
17
+ def self.discover_git_repo(path)
18
+ require "rugged"
19
+ Rugged::Repository.discover(path)
20
+ rescue Rugged::RepositoryError, Rugged::OSError
21
+ nil
22
+ end
23
+
24
+ def self.build_entries(dir_path, git_repo: nil, permissions: nil)
17
25
  entries = []
18
26
 
19
27
  Dir.foreach(dir_path) do |name|
@@ -28,9 +36,9 @@ module Swhid
28
36
  target_hash = Swhid.from_content(target_content).object_hash
29
37
  { name: name, type: :symlink, target: target_hash }
30
38
  elsif stat.directory?
31
- target_swhid = from_directory_path(full_path)
39
+ target_swhid = from_directory_path(full_path, git_repo: git_repo, permissions: permissions)
32
40
  { name: name, type: :dir, target: target_swhid.object_hash }
33
- elsif stat.executable?
41
+ elsif file_executable?(full_path, stat, git_repo, permissions)
34
42
  content = File.binread(full_path)
35
43
  target_hash = Swhid.from_content(content).object_hash
36
44
  { name: name, type: :exec, target: target_hash }
@@ -45,5 +53,42 @@ module Swhid
45
53
 
46
54
  entries
47
55
  end
56
+
57
+ def self.file_executable?(full_path, stat, git_repo, permissions = nil)
58
+ # Check explicit permissions map first (from tar extraction, etc.)
59
+ if permissions
60
+ mode = permissions[full_path] || permissions[File.expand_path(full_path)]
61
+ return (mode & 0o111) != 0 if mode
62
+ end
63
+
64
+ # Check Git index for tracked files
65
+ if git_repo
66
+ relative_path = relative_path_in_repo(full_path, git_repo)
67
+ if relative_path
68
+ entry = git_repo.index[relative_path]
69
+ if entry
70
+ mode = entry[:mode]
71
+ return (mode & 0o111) != 0
72
+ end
73
+ end
74
+ end
75
+
76
+ # Fall back to filesystem
77
+ stat.executable?
78
+ end
79
+
80
+ def self.relative_path_in_repo(full_path, git_repo)
81
+ repo_workdir = git_repo.workdir
82
+ return nil unless repo_workdir
83
+
84
+ full_path = File.expand_path(full_path)
85
+ repo_workdir = File.expand_path(repo_workdir)
86
+
87
+ return nil unless full_path.start_with?(repo_workdir)
88
+
89
+ relative = full_path.sub(repo_workdir, "")
90
+ relative = relative[1..] if relative.start_with?("/") || relative.start_with?("\\")
91
+ relative.tr("\\", "/")
92
+ end
48
93
  end
49
94
  end
data/lib/swhid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Swhid
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swhid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
@@ -35,6 +35,7 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - CHANGELOG.md
37
37
  - CODE_OF_CONDUCT.md
38
+ - LICENSE
38
39
  - README.md
39
40
  - Rakefile
40
41
  - benchmark/benchmark.rb
@@ -72,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
73
  - !ruby/object:Gem::Version
73
74
  version: '0'
74
75
  requirements: []
75
- rubygems_version: 3.6.9
76
+ rubygems_version: 4.0.1
76
77
  specification_version: 4
77
78
  summary: Generate and parse SoftWare Hash IDentifiers (SWHIDs)
78
79
  test_files: []