Skip to content

Commit

Permalink
fix: file copy issue with some volumes (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach authored Feb 24, 2025
1 parent 5778af2 commit 8aa0cc0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.7"

# YAML Anchors

x-deployment-env: &deployment-env
Expand Down Expand Up @@ -57,4 +55,4 @@ services:
condition: service_healthy
environment:
GITHUB_ACTION: ${GITHUB_ACTION:-}
PG_DATABASE_URL: ${PG_DATABASE_URL:-postgresql://postgres:password@postgres:5432/place_development}
PG_DATABASE_URL: ${PG_DATABASE_URL:-postgresql://postgres:password@postgres:5432/place_development}
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ shards:

placeos-models:
git: https://github.com/placeos/models.git
version: 9.62.4
version: 9.64.0

placeos-resource:
git: https://github.com/place-labs/resource.git
Expand Down
4 changes: 3 additions & 1 deletion spec/loader_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module PlaceOS::FrontendLoader
repository = example_repository(commit: "f7c6d8fb810c2be78722249e06bbfbda3d30d355")
repository.password = old_token
repository.save!
sleep 200.milliseconds

loader = Loader.new

Expand All @@ -60,12 +61,13 @@ module PlaceOS::FrontendLoader
repository.password = new_token
repository.password_will_change!
repository.save!
sleep 200.milliseconds

repository = repository.class.find!(repository.id.not_nil!)
loader.process_resource(:updated, repository).success?.should be_true

changefeed.stop
changes.size.should eq 3
changes.size.should eq 4

repository.reload!
encrypted = repository.password.not_nil!
Expand Down
19 changes: 19 additions & 0 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@ ActionController::Server.before(
ActionController::ErrorHandler.new(PlaceOS::FrontendLoader::PROD, ["X-Request-ID"]),
ActionController::LogHandler.new(ms: true)
)

# Crystal lang attempts to set permissions after copy
# remove after https://github.com/crystal-lang/crystal/pull/15510 merged
require "file"

class File < IO::FileDescriptor
def self.copy(src : String | Path, dst : String | Path) : Nil
open(src) do |s|
open(dst, "wb") do |d|
# TODO use sendfile or copy_file_range syscall. See #8926, #8919
IO.copy(s, d)
d.flush # need to flush in case permissions are read-only

# Set the permissions after the content is written in case src permissions is read-only
d.chmod(s.info.permissions) rescue nil
end
end
end
end
10 changes: 5 additions & 5 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ set -eu
# this function is called when Ctrl-C is sent
function trap_ctrlc ()
{
docker-compose down &> /dev/null
docker compose down &> /dev/null
exit 2
}

# initialise trap to call trap_ctrlc function
# when signal 2 (SIGINT) is received
trap "trap_ctrlc" 2

docker-compose pull -q
docker compose pull -q

docker-compose build -q
docker compose build -q

exit_code="0"

docker-compose run \
docker compose run \
--rm \
test $@ \
|| exit_code="$?"

docker-compose down &> /dev/null
docker compose down &> /dev/null

exit ${exit_code}

0 comments on commit 8aa0cc0

Please sign in to comment.