Skip to content

Commit

Permalink
Add tar 0.6 support
Browse files Browse the repository at this point in the history
resolves #286

this uses the upstream tar.
it also has support for changing ownership of the files unpacked (which the keter implementation also seemed to manage).

this also deletes the stack based ci in favor of a cabal based ci, it broke for some reason and I didn't want to play stack whackamole.

use upstream unpack

bump filepath

forM more

import forM

trash result

don't use a traverse but a fold

update changelog

add extra deps

clear stack

add cabal based action

drop windows support

clear stack based ci

Add note on changing to cabal ci

I just don't want to figure out why this broke.

bump keter
  • Loading branch information
jappeace committed Dec 28, 2023
1 parent 16bd88c commit 20a33d9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 94 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/cabal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on: [pull_request]
jobs:
build:

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
ghc: # should mirror current stable releases: https://www.haskell.org/ghc/download.html
- '9.8'
- '9.6'
- '9.4'
- '9.2'
os: [ubuntu-latest, macOS-latest]

steps:
- uses: actions/checkout@v3
- uses: haskell/actions/setup@v2 # https://github.com/haskell/actions/tree/main/setup#haskellactionssetup
with:
ghc-version: ${{ matrix.ghc }}

- name: Cabal cache
uses: actions/cache@v3
env:
cache-name: cache-cabal
with:
path: ~/.cabal
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Cabal update
run: cabal update
- name: Build using cabal
run: cabal build all
- name: Test
run: cabal test all
44 changes: 0 additions & 44 deletions .github/workflows/stack.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
accidentally flipped. PR #282
* In case reading any one of `*-host-response-file` fails, keter now logs a warning,
and falls back to builtin defaults. Before 2.1.3, this is a fatal error.
* Add support for tar 0.6, drop NIH tar unpack.
+ Change CI to be cabal based instead of stack.

## 2.1.2

Expand Down
6 changes: 3 additions & 3 deletions keter.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: keter
version: 2.1.2
version: 2.1.3
synopsis:
Web application deployment manager, focusing on Haskell web frameworks. It mitigates downtime.

Expand Down Expand Up @@ -44,7 +44,7 @@ library
containers >=0.6.4 && <0.7 || ^>=0.7,
directory >=1.3.6 && <1.4,
fast-logger >=3.0.0 && <4.0.0,
filepath >=1.4.2 && <1.5,
filepath >=1.4.2 && <1.6,
fsnotify >=0.3.0 && <0.5,
http-client >=0.7.11 && <0.8,
http-conduit >=2.3.8 && <2.4,
Expand All @@ -60,7 +60,7 @@ library
random >=1.2.1 && <1.3,
regex-tdfa >=1.3.1 && <1.4,
stm >=2.5.0 && <2.6,
tar >=0.5.1 && <0.6,
tar >=0.5.1 && <0.7,
template-haskell >=2.17.0 && <3.0,
text >=1.2.5 && <3.0,
time >=1.9.3 && <2.0,
Expand Down
56 changes: 9 additions & 47 deletions src/Keter/TempTarball.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import qualified Codec.Archive.Tar.Check as Tar
import qualified Codec.Archive.Tar.Entry as Tar

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, ubuntu-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, macOS-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, ubuntu-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, ubuntu-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, ubuntu-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, macOS-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, macOS-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant

Check warning on line 15 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, macOS-latest)

The qualified import of ‘Codec.Archive.Tar.Entry’ is redundant
import Codec.Compression.GZip (decompress)
import Control.Exception (bracket, bracketOnError, throwIO)

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, ubuntu-latest)

The import of ‘bracket’

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, macOS-latest)

The import of ‘bracket’

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, ubuntu-latest)

The import of ‘bracket’

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, ubuntu-latest)

The import of ‘bracket’

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, ubuntu-latest)

The import of ‘bracket’

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, macOS-latest)

The import of ‘bracket’

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, macOS-latest)

The import of ‘bracket’

Check warning on line 17 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, macOS-latest)

The import of ‘bracket’
import Control.Monad (unless, when)
import Control.Monad (unless, when, forM)

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, ubuntu-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, macOS-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, ubuntu-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, ubuntu-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, ubuntu-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, macOS-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, macOS-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant

Check warning on line 18 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, macOS-latest)

The import of ‘unless’ from module ‘Control.Monad’ is redundant
import qualified Data.ByteString.Lazy as L
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, ubuntu-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, macOS-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, ubuntu-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.2, ubuntu-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, ubuntu-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.4, macOS-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.8, macOS-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant

Check warning on line 20 in src/Keter/TempTarball.hs

View workflow job for this annotation

GitHub Actions / build (9.6, macOS-latest)

The import of ‘Data.ByteString.Unsafe’ is redundant
import qualified Data.IORef as I
Expand Down Expand Up @@ -67,51 +67,13 @@ unpackTempTar :: Maybe (UserID, GroupID)
unpackTempTar muid tf bundle appname withDir = do
lbs <- L.readFile bundle
bracketOnError (getFolder muid tf appname) D.removeDirectoryRecursive $ \dir -> do
unpackTar muid dir $ Tar.read $ decompress lbs
D.createDirectoryIfMissing True dir
let entries = Tar.read $ decompress lbs
Tar.unpack dir entries
_ <- forM muid $ \perms ->
Tar.foldEntries (setEntryPermission perms) (pure ()) throwIO entries
withDir dir

unpackTar :: Maybe (UserID, GroupID)
-> FilePath
-> Tar.Entries Tar.FormatError
-> IO ()
unpackTar muid dir =
loop . Tar.checkSecurity
where
loop Tar.Done = return ()
loop (Tar.Fail e) = either throwIO throwIO e
loop (Tar.Next e es) = go e >> loop es

go e = do
let fp = dir </> Tar.entryPath e
case Tar.entryContent e of
Tar.NormalFile lbs _ -> do
case muid of
Nothing -> D.createDirectoryIfMissing True $ F.takeDirectory fp
Just (uid, gid) -> createTreeUID uid gid $ F.takeDirectory fp
let write fd bs = unsafeUseAsCStringLen bs $ \(ptr, len) -> do
_ <- fdWriteBuf fd (castPtr ptr) (fromIntegral len)
return ()
bracket
(do
fd <- createFile fp $ Tar.entryPermissions e
setFdOption fd CloseOnExec True
case muid of
Nothing -> return ()
Just (uid, gid) -> setFdOwnerAndGroup fd uid gid
return fd)
closeFd
(\fd -> mapM_ (write fd) (L.toChunks lbs))
_ -> return ()

-- | Create a directory tree, setting the uid and gid of all newly created
-- folders.
createTreeUID :: UserID -> GroupID -> FilePath -> IO ()
createTreeUID uid gid =
go
where
go fp = do
exists <- D.doesDirectoryExist fp
unless exists $ do
go $ F.takeDirectory fp
D.createDirectoryIfMissing False fp
setOwnerAndGroup fp uid gid
setEntryPermission :: (UserID, GroupID) -> Tar.Entry -> IO () -> IO ()
setEntryPermission (uid, gid) entry io =
io >> setOwnerAndGroup (Tar.entryPath entry) uid gid

0 comments on commit 20a33d9

Please sign in to comment.