Skip to content

Commit 20a33d9

Browse files
committed
Add tar 0.6 support
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
1 parent 16bd88c commit 20a33d9

File tree

5 files changed

+51
-94
lines changed

5 files changed

+51
-94
lines changed

.github/workflows/cabal.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
on: [pull_request]
2+
jobs:
3+
build:
4+
5+
runs-on: ${{ matrix.os }}
6+
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
ghc: # should mirror current stable releases: https://www.haskell.org/ghc/download.html
11+
- '9.8'
12+
- '9.6'
13+
- '9.4'
14+
- '9.2'
15+
os: [ubuntu-latest, macOS-latest]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: haskell/actions/setup@v2 # https://github.com/haskell/actions/tree/main/setup#haskellactionssetup
20+
with:
21+
ghc-version: ${{ matrix.ghc }}
22+
23+
- name: Cabal cache
24+
uses: actions/cache@v3
25+
env:
26+
cache-name: cache-cabal
27+
with:
28+
path: ~/.cabal
29+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
30+
restore-keys: |
31+
${{ runner.os }}-build-${{ env.cache-name }}-
32+
- name: Cabal update
33+
run: cabal update
34+
- name: Build using cabal
35+
run: cabal build all
36+
- name: Test
37+
run: cabal test all

.github/workflows/stack.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

ChangeLog.md

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

1012
## 2.1.2
1113

keter.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: keter
3-
version: 2.1.2
3+
version: 2.1.3
44
synopsis:
55
Web application deployment manager, focusing on Haskell web frameworks. It mitigates downtime.
66

@@ -44,7 +44,7 @@ library
4444
containers >=0.6.4 && <0.7 || ^>=0.7,
4545
directory >=1.3.6 && <1.4,
4646
fast-logger >=3.0.0 && <4.0.0,
47-
filepath >=1.4.2 && <1.5,
47+
filepath >=1.4.2 && <1.6,
4848
fsnotify >=0.3.0 && <0.5,
4949
http-client >=0.7.11 && <0.8,
5050
http-conduit >=2.3.8 && <2.4,
@@ -60,7 +60,7 @@ library
6060
random >=1.2.1 && <1.3,
6161
regex-tdfa >=1.3.1 && <1.4,
6262
stm >=2.5.0 && <2.6,
63-
tar >=0.5.1 && <0.6,
63+
tar >=0.5.1 && <0.7,
6464
template-haskell >=2.17.0 && <3.0,
6565
text >=1.2.5 && <3.0,
6666
time >=1.9.3 && <2.0,

src/Keter/TempTarball.hs

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import qualified Codec.Archive.Tar.Check as Tar
1515
import qualified Codec.Archive.Tar.Entry as Tar
1616
import Codec.Compression.GZip (decompress)
1717
import Control.Exception (bracket, bracketOnError, throwIO)
18-
import Control.Monad (unless, when)
18+
import Control.Monad (unless, when, forM)
1919
import qualified Data.ByteString.Lazy as L
2020
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
2121
import qualified Data.IORef as I
@@ -67,51 +67,13 @@ unpackTempTar :: Maybe (UserID, GroupID)
6767
unpackTempTar muid tf bundle appname withDir = do
6868
lbs <- L.readFile bundle
6969
bracketOnError (getFolder muid tf appname) D.removeDirectoryRecursive $ \dir -> do
70-
unpackTar muid dir $ Tar.read $ decompress lbs
70+
D.createDirectoryIfMissing True dir
71+
let entries = Tar.read $ decompress lbs
72+
Tar.unpack dir entries
73+
_ <- forM muid $ \perms ->
74+
Tar.foldEntries (setEntryPermission perms) (pure ()) throwIO entries
7175
withDir dir
7276

73-
unpackTar :: Maybe (UserID, GroupID)
74-
-> FilePath
75-
-> Tar.Entries Tar.FormatError
76-
-> IO ()
77-
unpackTar muid dir =
78-
loop . Tar.checkSecurity
79-
where
80-
loop Tar.Done = return ()
81-
loop (Tar.Fail e) = either throwIO throwIO e
82-
loop (Tar.Next e es) = go e >> loop es
83-
84-
go e = do
85-
let fp = dir </> Tar.entryPath e
86-
case Tar.entryContent e of
87-
Tar.NormalFile lbs _ -> do
88-
case muid of
89-
Nothing -> D.createDirectoryIfMissing True $ F.takeDirectory fp
90-
Just (uid, gid) -> createTreeUID uid gid $ F.takeDirectory fp
91-
let write fd bs = unsafeUseAsCStringLen bs $ \(ptr, len) -> do
92-
_ <- fdWriteBuf fd (castPtr ptr) (fromIntegral len)
93-
return ()
94-
bracket
95-
(do
96-
fd <- createFile fp $ Tar.entryPermissions e
97-
setFdOption fd CloseOnExec True
98-
case muid of
99-
Nothing -> return ()
100-
Just (uid, gid) -> setFdOwnerAndGroup fd uid gid
101-
return fd)
102-
closeFd
103-
(\fd -> mapM_ (write fd) (L.toChunks lbs))
104-
_ -> return ()
105-
106-
-- | Create a directory tree, setting the uid and gid of all newly created
107-
-- folders.
108-
createTreeUID :: UserID -> GroupID -> FilePath -> IO ()
109-
createTreeUID uid gid =
110-
go
111-
where
112-
go fp = do
113-
exists <- D.doesDirectoryExist fp
114-
unless exists $ do
115-
go $ F.takeDirectory fp
116-
D.createDirectoryIfMissing False fp
117-
setOwnerAndGroup fp uid gid
77+
setEntryPermission :: (UserID, GroupID) -> Tar.Entry -> IO () -> IO ()
78+
setEntryPermission (uid, gid) entry io =
79+
io >> setOwnerAndGroup (Tar.entryPath entry) uid gid

0 commit comments

Comments
 (0)