Skip to content

Commit

Permalink
Skip scan if file does not exist
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
apmiller108 committed Mar 11, 2018
1 parent 3f3a377 commit 13dc29c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CRYSTAL_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ process_runner = Sentry::ProcessRunner.new(
build_args: [], # Array of String
run_args: [], # Array of String
should_build: true, # Bool
files: [] # Array of String
files: [], # Array of String
ignore: [] # Array of String
)
```
```
16 changes: 11 additions & 5 deletions src/sentry.cr
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module Sentry
property display_name : String
property should_build = true
property files = [] of String
property ignore_regexes = [] of Regex
property ignore = [] of Regex

def initialize(
@display_name : String,
Expand All @@ -158,11 +158,11 @@ module Sentry
@build_args : Array(String) = [] of String,
@run_args : Array(String) = [] of String,
files = [] of String,
ignore_regexes = [] of String,
ignore = [] of String,
should_build = true
)
@files = files
@ignore_regexes = ignore_regexes.map { |regex| Regex.new(regex.strip("/")) }
@ignore = ignore.map { |regex| Regex.new(regex.strip("/")) }
@should_build = should_build
@should_kill = false
@app_built = false
Expand Down Expand Up @@ -200,6 +200,12 @@ module Sentry
File.stat(file).mtime.to_s("%Y%m%d%H%M%S")
end

private def ignored?(file : String)
@ignore.any? do |regex|
regex === file || regex === file.split("/").last
end
end

# Compiles and starts the application
#
def start_app
Expand All @@ -214,14 +220,14 @@ module Sentry
end
end

# Scans all of the `@files`, expect where matched with `@ignore_regexes`
# Scans all of the `@files`, expect where matched with `@ignore`
#
def scan_files
file_changed = false
app_process = @app_process
files = @files
Dir.glob(files) do |file|
next if @ignore_regexes.any? { |r| r === file || r === file.split("/").last }
next if !File.exists?(file) || ignored?(file)
timestamp = get_timestamp(file)
if FILE_TIMESTAMPS[file]? && FILE_TIMESTAMPS[file] != timestamp
FILE_TIMESTAMPS[file] = timestamp
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if Sentry::Config.shard_name
run_args: config.run_args,
should_build: config.should_build?,
files: config.watch,
ignore_regexes: config.ignore
ignore: config.ignore
)

process_runner.run
Expand Down

0 comments on commit 13dc29c

Please sign in to comment.