Skip to content

Commit 963eb07

Browse files
metsmakristelmerilain
authored andcommitted
Calculate file size on demand
IB-8711, Fixes #682 Signed-off-by: Raul Metsma <[email protected]>
1 parent 29450e5 commit 963eb07

File tree

4 files changed

+47
-48
lines changed

4 files changed

+47
-48
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
cd /Library
6464
zip -q -r ${OLDPWD}/libdigidocpp.${{ matrix.target }}.zip libdigidocpp.*
6565
- name: Archive artifacts
66-
uses: actions/upload-artifact@v4
66+
uses: actions/upload-artifact@v5
6767
with:
6868
name: ${{ matrix.target }}
6969
path: |
@@ -84,32 +84,24 @@ jobs:
8484
steps:
8585
- name: Checkout
8686
uses: actions/checkout@v5
87-
- name: Expose Android NDK env
88-
shell: bash
89-
run: |
90-
echo "ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> "$GITHUB_ENV"
91-
echo "ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME" >> "$GITHUB_ENV"
9287
- name: Cache vcpkg
9388
uses: actions/cache@v4
9489
with:
9590
path: ${{ github.workspace }}/vcpkg_cache
9691
key: vcpkg-${{ matrix.target }}-${{ hashFiles('vcpkg.json', 'vcpkg-ports/**') }}
97-
- name: Prepare vcpkg
98-
uses: lukka/run-vcpkg@v11
99-
with:
100-
vcpkgJsonGlob: ./vcpkg.json
101-
runVcpkgInstall: true
92+
- name: Build
10293
env:
10394
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg_cache,readwrite
104-
VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}
105-
- name: Build
10695
run: |
96+
export VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT
97+
export ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME
98+
export ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME
10799
cmake --preset ${{ matrix.target }} "-GUnix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo
108100
cmake --build --preset ${{ matrix.target }}
109101
cmake --build --preset ${{ matrix.target }} --target install/strip
110102
zip -q -r libdigidocpp.${{ matrix.target }}.zip libdigidocpp.${{ matrix.target }}
111103
- name: Archive artifacts
112-
uses: actions/upload-artifact@v4
104+
uses: actions/upload-artifact@v5
113105
with:
114106
name: ${{ matrix.target }}
115107
path: |
@@ -120,7 +112,7 @@ jobs:
120112
container: fedora:${{ matrix.container }}
121113
strategy:
122114
matrix:
123-
container: [41, 42, 43, rawhide]
115+
container: [42, 43, rawhide]
124116
steps:
125117
- name: Install Deps
126118
run: |
@@ -134,7 +126,7 @@ jobs:
134126
cmake --build build
135127
cmake --build build --target package
136128
- name: Archive artifacts
137-
uses: actions/upload-artifact@v4
129+
uses: actions/upload-artifact@v5
138130
with:
139131
name: fedora_${{ matrix.container }}
140132
path: build/libdigidocpp*.rpm
@@ -177,7 +169,7 @@ jobs:
177169
- name: Lintian
178170
run: lintian *.deb;
179171
- name: Archive artifacts
180-
uses: actions/upload-artifact@v4
172+
uses: actions/upload-artifact@v5
181173
with:
182174
name: ${{ matrix.dist }}_${{ matrix.ver }}_${{ matrix.arch }}
183175
path: libdigidocpp*.*
@@ -206,16 +198,6 @@ jobs:
206198
with:
207199
path: ${{ github.workspace }}/vcpkg_cache
208200
key: vcpkg-${{ matrix.toolset }}-${{ matrix.platform }}-${{ hashFiles('vcpkg.json', 'vcpkg-ports/**') }}
209-
- name: Prepare vcpkg
210-
uses: lukka/run-vcpkg@v11
211-
with:
212-
vcpkgJsonGlob: ./vcpkg.json
213-
runVcpkgInstall: true
214-
runVcpkgFormatString: "[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`, `--x-feature`, `tests`]"
215-
env:
216-
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg_cache,readwrite
217-
VCPKG_DEFAULT_TRIPLET: ${{ matrix.platform }}-windows
218-
VCPKG_INSTALLED_DIR: ${{ github.workspace }}/vcpkg_installed_${{ matrix.platform }}
219201
- name: Install dependencies
220202
run: winget install --silent --accept-source-agreements --accept-package-agreements swig doxygen
221203
- uses: actions/setup-java@v4
@@ -228,14 +210,17 @@ jobs:
228210
python-version: 3.12
229211
architecture: ${{ matrix.platform }}
230212
- name: Build
213+
env:
214+
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg_cache,readwrite
231215
run: |
232216
$swig = (Get-Item "$env:LOCALAPPDATA\Microsoft\WinGet\Links\swig.exe").Target
233217
& "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvarsall.bat" ${{ matrix.setenv }} "&&" pwsh build.ps1 `
218+
-vcpkg "C:/vcpkg/vcpkg.exe" `
234219
-swig $swig `
235220
-doxygen "C:/Program files/doxygen/bin/doxygen.exe" `
236221
-boost
237222
- name: Archive artifacts
238-
uses: actions/upload-artifact@v4
223+
uses: actions/upload-artifact@v5
239224
with:
240225
name: msi_${{ matrix.toolset }}_${{ matrix.platform }}
241226
path: ./*.msi

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ param(
33
[string]$libdigidocpp = $PSScriptRoot,
44
[string]$platform = $env:PLATFORM,
55
[string]$build_number = $(if ($null -eq $env:BUILD_NUMBER) {"0"} else {$env:BUILD_NUMBER}),
6-
[string]$msiversion = "4.3.0.$build_number",
6+
[string]$msiversion = "4.4.0.$build_number",
77
[string]$msi_name = "libdigidocpp-$msiversion$env:VER_SUFFIX.$platform.msi",
88
[string]$git = "git.exe",
99
[string]$vcpkg = "vcpkg\vcpkg.exe",

src/DataFile.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,17 @@ using namespace std;
8383
DataFile::DataFile() = default;
8484
DataFile::~DataFile() = default;
8585

86+
struct DataFilePrivate::Private {
87+
optional<unsigned long> size;
88+
};
8689

8790
DataFilePrivate::DataFilePrivate(unique_ptr<istream> &&is, string filename, string mediatype, string id)
88-
: m_is(std::move(is))
91+
: d(make_unique<Private>())
92+
, m_is(std::move(is))
8993
, m_id(std::move(id))
9094
, m_filename(std::move(filename))
9195
, m_mediatype(std::move(mediatype))
9296
{
93-
m_is->seekg(0, istream::end);
94-
istream::pos_type pos = m_is->tellg();
95-
m_size = pos < 0 ? 0 : (unsigned long)pos;
9697
}
9798

9899
void DataFilePrivate::digest(const Digest &digest) const
@@ -109,6 +110,17 @@ vector<unsigned char> DataFilePrivate::calcDigest(const string &method) const
109110
return d.result();
110111
}
111112

113+
unsigned long DataFilePrivate::fileSize() const
114+
{
115+
if(d->size.has_value())
116+
return d->size.value();
117+
m_is->clear();
118+
m_is->seekg(0, istream::end);
119+
istream::pos_type pos = m_is->tellg();
120+
d->size.emplace(pos < 0 ? 0 : (unsigned long)pos);
121+
return d->size.value();
122+
}
123+
112124
void DataFilePrivate::saveAs(const string& path) const
113125
{
114126
ofstream ofs(File::encodeName(path), ofstream::binary);

src/DataFile_p.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <istream>
2525
#include <memory>
26+
#include <optional>
2627

2728
namespace digidoc
2829
{
@@ -31,20 +32,21 @@ class Digest;
3132
class DataFilePrivate final: public DataFile
3233
{
3334
public:
34-
DataFilePrivate(std::unique_ptr<std::istream> &&is, std::string filename, std::string mediatype, std::string id = {});
35-
36-
std::string id() const final { return m_id.empty() ? m_filename : m_id; }
37-
std::string fileName() const final { return m_filename; }
38-
unsigned long fileSize() const final { return m_size; }
39-
std::string mediaType() const final { return m_mediatype; }
40-
41-
void digest(const Digest &method) const;
42-
std::vector<unsigned char> calcDigest(const std::string &method) const final;
43-
void saveAs(std::ostream &os) const final;
44-
void saveAs(const std::string& path) const final;
45-
46-
std::unique_ptr<std::istream> m_is;
47-
std::string m_id, m_filename, m_mediatype;
48-
unsigned long m_size;
35+
DataFilePrivate(std::unique_ptr<std::istream> &&is, std::string filename, std::string mediatype, std::string id = {});
36+
37+
std::string id() const final { return m_id.empty() ? m_filename : m_id; }
38+
std::string fileName() const final { return m_filename; }
39+
unsigned long fileSize() const final;
40+
std::string mediaType() const final { return m_mediatype; }
41+
42+
void digest(const Digest &method) const;
43+
std::vector<unsigned char> calcDigest(const std::string &method) const final;
44+
void saveAs(std::ostream &os) const final;
45+
void saveAs(const std::string& path) const final;
46+
47+
struct Private;
48+
std::unique_ptr<Private> d;
49+
std::unique_ptr<std::istream> m_is;
50+
std::string m_id, m_filename, m_mediatype;
4951
};
5052
}

0 commit comments

Comments
 (0)