Skip to content

Commit 13dc29c

Browse files
committed
Skip scan if file does not exist
- Skip caching timestamps for symbolic links by checking if `File.exists?(file)`. This resolves exception: `Unable to get stat for './src/my_file.cr': No such file or directory (Errno)` - Update API documentation with `ignore` reference - rename `ignore_regexes` to `ignore`
1 parent 3f3a377 commit 13dc29c

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

CRYSTAL_API.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ process_runner = Sentry::ProcessRunner.new(
6060
build_args: [], # Array of String
6161
run_args: [], # Array of String
6262
should_build: true, # Bool
63-
files: [] # Array of String
63+
files: [], # Array of String
64+
ignore: [] # Array of String
6465
)
65-
```
66+
```

src/sentry.cr

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module Sentry
149149
property display_name : String
150150
property should_build = true
151151
property files = [] of String
152-
property ignore_regexes = [] of Regex
152+
property ignore = [] of Regex
153153

154154
def initialize(
155155
@display_name : String,
@@ -158,11 +158,11 @@ module Sentry
158158
@build_args : Array(String) = [] of String,
159159
@run_args : Array(String) = [] of String,
160160
files = [] of String,
161-
ignore_regexes = [] of String,
161+
ignore = [] of String,
162162
should_build = true
163163
)
164164
@files = files
165-
@ignore_regexes = ignore_regexes.map { |regex| Regex.new(regex.strip("/")) }
165+
@ignore = ignore.map { |regex| Regex.new(regex.strip("/")) }
166166
@should_build = should_build
167167
@should_kill = false
168168
@app_built = false
@@ -200,6 +200,12 @@ module Sentry
200200
File.stat(file).mtime.to_s("%Y%m%d%H%M%S")
201201
end
202202

203+
private def ignored?(file : String)
204+
@ignore.any? do |regex|
205+
regex === file || regex === file.split("/").last
206+
end
207+
end
208+
203209
# Compiles and starts the application
204210
#
205211
def start_app
@@ -214,14 +220,14 @@ module Sentry
214220
end
215221
end
216222

217-
# Scans all of the `@files`, expect where matched with `@ignore_regexes`
223+
# Scans all of the `@files`, expect where matched with `@ignore`
218224
#
219225
def scan_files
220226
file_changed = false
221227
app_process = @app_process
222228
files = @files
223229
Dir.glob(files) do |file|
224-
next if @ignore_regexes.any? { |r| r === file || r === file.split("/").last }
230+
next if !File.exists?(file) || ignored?(file)
225231
timestamp = get_timestamp(file)
226232
if FILE_TIMESTAMPS[file]? && FILE_TIMESTAMPS[file] != timestamp
227233
FILE_TIMESTAMPS[file] = timestamp

src/sentry_cli.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ if Sentry::Config.shard_name
8282
run_args: config.run_args,
8383
should_build: config.should_build?,
8484
files: config.watch,
85-
ignore_regexes: config.ignore
85+
ignore: config.ignore
8686
)
8787

8888
process_runner.run

0 commit comments

Comments
 (0)