swhid 0.3.1 → 0.4.1

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: 55ef264a7547cae4c3e201c8c4b745ea42437173efd681623bf7307c0bf58b0d
4
+ data.tar.gz: d851e19c5511018c5ded8e853306650414b1708a99fd10837f2e6d62a6266f13
5
5
  SHA512:
6
- metadata.gz: ad64d5ffad60fde8ec7399abcd63af7c34ae203c54f469df9866283864f1850c0f9b1c112ab89300c7ea52f56d5809189bbe6ec0bd2c9fc2ed85510daa3b2d37
7
- data.tar.gz: a44ef79ecd7a5d64f4d29c56f470b749ab61eac0d3f3ddd29c8b4798f334fa3f43222b8b463819f221e5687ca1355f7c23b7754be43a739009aafa4adba3e3cd
6
+ metadata.gz: db250c4038a39aa01d3a73c83a1d11ebf907a7465649b69cbff3ed3c9b44e758519c2573ca949fabc996b43ae737a5259d41c1d143ecb1dc980813dc2d6c54cc
7
+ data.tar.gz: abaa8a4ca6c33cc718c28f573641a207c6458c8dcb4df4440759583cd1dd9394a60c507c0d29795e4149218b1bcba8b212ee83114e1bbf6a6f0ebe99135328ef
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.1] - 2026-01-13
4
+
5
+ ### Fixed
6
+ - Resolve symlinks when matching paths for Git index permission lookups
7
+
8
+ ## [0.4.0] - 2026-01-12
9
+
10
+ ### Added
11
+ - Windows support for directory SWHID computation
12
+ - File permissions read from Git index on Windows where filesystem permissions unavailable
13
+ - Optional `permissions:` parameter for `FromFilesystem.from_directory_path` to pass explicit file modes
14
+ - CI testing on Windows (Ruby 3.4 and 4.0)
15
+
16
+ ### Changed
17
+ - Archive extraction in tests now uses pure Ruby (Zlib/TarReader/Zip) instead of shell commands
18
+
3
19
  ## [0.3.1] - 2025-11-23
4
20
 
5
21
  ### 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,46 @@ 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
+ real_path = File.realpath(full_path) rescue File.expand_path(full_path)
61
+ mode = permissions[full_path] || permissions[real_path]
62
+ return (mode & 0o111) != 0 if mode
63
+ end
64
+
65
+ # Check Git index for tracked files
66
+ if git_repo
67
+ relative_path = relative_path_in_repo(full_path, git_repo)
68
+ if relative_path
69
+ entry = git_repo.index[relative_path]
70
+ if entry
71
+ mode = entry[:mode]
72
+ return (mode & 0o111) != 0
73
+ end
74
+ end
75
+ end
76
+
77
+ # Fall back to filesystem
78
+ stat.executable?
79
+ end
80
+
81
+ def self.relative_path_in_repo(full_path, git_repo)
82
+ repo_workdir = git_repo.workdir
83
+ return nil unless repo_workdir
84
+
85
+ # Use realpath to resolve symlinks (e.g., /tmp -> /private/tmp on macOS)
86
+ full_path = File.realpath(full_path) rescue File.expand_path(full_path)
87
+ repo_workdir = File.realpath(repo_workdir) rescue File.expand_path(repo_workdir)
88
+
89
+ # Ensure repo_workdir ends with separator for proper prefix matching
90
+ repo_workdir = repo_workdir.chomp("/").chomp("\\") + "/"
91
+
92
+ return nil unless full_path.start_with?(repo_workdir)
93
+
94
+ relative = full_path.sub(repo_workdir, "")
95
+ relative.tr("\\", "/")
96
+ end
48
97
  end
49
98
  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.1"
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.1
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: []