Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
cef0d65
Update .gitignore
go-while Jun 10, 2025
c81f3fc
add basic Proxy module
go-while Jun 10, 2025
60a886d
typo
go-while Jun 10, 2025
562e485
Update Server.go
go-while Jun 10, 2025
23926c5
Update Server.go
go-while Jun 10, 2025
b7fe690
Update Server.go
go-while Jun 10, 2025
f4b7bb0
Update NetConn.go
go-while Jun 10, 2025
862e081
Update NetConn.go
go-while Jun 10, 2025
6cb50f4
Update Server.go
go-while Jun 10, 2025
071e916
Update Server.go
go-while Jun 10, 2025
49158da
Update Server.go
go-while Jun 10, 2025
85abe14
Update Server.go
go-while Jun 10, 2025
4ce9b42
Update Server.go
go-while Jun 10, 2025
962c3e6
Update main.go
go-while Jun 10, 2025
cb7ce6a
Update Server.go
go-while Jun 10, 2025
92c9510
Update Server.go
go-while Jun 10, 2025
1bf9787
Update Server.go
go-while Jun 10, 2025
2993d43
Update Flags.go
go-while Jun 10, 2025
f844427
Update Flags.go
go-while Jun 10, 2025
1d5b882
Update Flags.go
go-while Jun 10, 2025
5b97e70
moving funcs to files
go-while Jun 10, 2025
bc95d1f
Update Utils.go
go-while Jun 10, 2025
e8223a9
Update Session.go
go-while Jun 10, 2025
8344089
Update main.go
go-while Jun 10, 2025
da975c6
Update Utils.go
go-while Jun 10, 2025
296f3b3
Merge branch 'testing' of ssh://github.com/go-while/NZBreX into testing
go-while Jun 10, 2025
82ca466
Update Utils.go
go-while Jun 10, 2025
f87d039
Update ConnPool.go
go-while Jun 10, 2025
a7a7dd1
Update Proxy.go
go-while Jun 11, 2025
e40ba2d
Update Server.go
go-while Jun 11, 2025
c559a56
Update Config.go
go-while Jun 11, 2025
b2eb2f4
Update Proxy.go
go-while Jun 11, 2025
74b0455
Update Server.go
go-while Jun 11, 2025
ef408f2
Update Server.go
go-while Jun 11, 2025
69027ab
Update Utils.go
go-while Jun 11, 2025
fa1e2ea
Update Utils.go
go-while Jun 11, 2025
54cbcdc
Update Session.go
go-while Jun 11, 2025
e47ff46
Update Utils.go
go-while Jun 11, 2025
dc497ee
Update Utils.go
go-while Jun 11, 2025
7c9e458
Update Utils.go
go-while Jun 11, 2025
736c090
Update Utils.go
go-while Jun 11, 2025
b38836f
Update Flags.go
go-while Jun 11, 2025
5e81c70
patches
go-while Aug 22, 2025
151a9c0
Merge pull request #66 from go-while/copilot/fix-65
go-while Aug 22, 2025
ea5d3e4
Merge branch 'testing' of ssh://github.com/go-while/NZBreX into testing
go-while Aug 22, 2025
f3f1a85
Update Workflows
go-while Aug 22, 2025
9d2fbb3
test build
go-while Oct 14, 2025
ff6e13c
Update build_and_publish_test.yml
go-while Oct 14, 2025
3896869
Update build_and_publish_test.yml
go-while Oct 14, 2025
062c664
Update build_and_publish_test.yml
go-while Oct 14, 2025
eeb4d24
Update build_and_publish_test.yml
go-while Oct 14, 2025
7c54911
Update build_and_publish_test.yml
go-while Oct 14, 2025
95e1c6f
Update build_and_publish_test.yml
go-while Oct 14, 2025
8861850
Update build_and_publish_test.yml
go-while Oct 14, 2025
6340511
Update build_and_publish_test.yml
go-while Oct 14, 2025
cbbc0da
Update build_and_publish_test.yml
go-while Oct 14, 2025
ec99277
Update codeql.yml
go-while Oct 14, 2025
e6e0b3c
test 1.25.1
go-while Oct 14, 2025
47d7b98
build scripts
go-while Oct 14, 2025
e0b7ced
Update codeql.yml
go-while Oct 14, 2025
8ad2d83
Update ProxyHelper.go
go-while Oct 14, 2025
2ec6267
Update Server.go
go-while Oct 14, 2025
674a7e8
Update Server.go
go-while Oct 14, 2025
0654c56
Potential fix for code scanning alert no. 71: Clear-text logging of s…
go-while Oct 14, 2025
6a36f32
try patch
go-while Oct 14, 2025
011e313
Merge branch 'testing' of ssh://github.com/go-while/NZBreX into testing
go-while Oct 14, 2025
8996aab
Update codeql.yml
go-while Oct 14, 2025
15ff454
Update Server.go
go-while Oct 14, 2025
8031f5f
testing
go-while Oct 14, 2025
01286ff
testing
go-while Oct 14, 2025
d203fe0
testing
go-while Oct 14, 2025
6d96418
Update build_and_publish_test.yml
go-while Oct 14, 2025
d238ed9
Update build_and_publish_test.yml
go-while Oct 14, 2025
06fe0c0
Create grep.sh
go-while Oct 14, 2025
255b8eb
Merge branch 'main' into testing
go-while Oct 14, 2025
7e50098
0.0.6-test-p2
go-while Oct 14, 2025
19fb962
Update Session.go
go-while Oct 14, 2025
9266e6d
Update build_and_publish_test.yml
go-while Oct 14, 2025
7c73aab
Update build_and_publish_test.yml
go-while Oct 14, 2025
fda5371
go 1.25.3
go-while Oct 14, 2025
6efaa7b
AI fucked up
go-while Oct 14, 2025
49b3fc5
I too, !proxy
go-while Oct 14, 2025
0001efe
comment for AI
go-while Oct 14, 2025
1e07959
item.FlagError(provider.id)
go-while Oct 15, 2025
406238b
item.FlagError
go-while Oct 15, 2025
bd22e72
comment
go-while Oct 15, 2025
c037781
Update build_and_publish_test.yml
go-while Oct 15, 2025
0f6547d
debugs
go-while Oct 15, 2025
c0bc43f
proxy: replace tpReader/tpWriter with CliTp
go-while Oct 15, 2025
4c2c19b
compiler
go-while Oct 15, 2025
50da338
test build
go-while Oct 15, 2025
9533397
test mac arm
go-while Oct 15, 2025
98b1c6f
retry mac build
go-while Oct 15, 2025
a53498a
test build
go-while Oct 15, 2025
0721cfb
test build
go-while Oct 15, 2025
d56c03e
test build
go-while Oct 15, 2025
70f510f
test build
go-while Oct 15, 2025
793ace7
test build
go-while Oct 15, 2025
e9930cc
test mac
go-while Oct 15, 2025
d9d9868
will darwin arm64 compile with amd64?
go-while Oct 15, 2025
6090a5d
try fix filenames
go-while Oct 15, 2025
4b3ca15
explain error
go-while Oct 15, 2025
fda4b9a
fail quick on errors
go-while Oct 15, 2025
5844e8c
fix connection problems
go-while Oct 16, 2025
44c2ef7
test windows compilation
go-while Oct 16, 2025
8cb4933
flag errors
go-while Oct 17, 2025
ed093db
conn & memlim
go-while Oct 17, 2025
fa95a52
Update Config.go
go-while Oct 17, 2025
cf32eeb
debugs & mutex
go-while Oct 17, 2025
793f153
counter
go-while Oct 17, 2025
ba3538c
conn timeouts
go-while Oct 17, 2025
8d7ad8b
Update Workers.go
go-while Oct 17, 2025
5c0f295
testing
go-while Oct 17, 2025
4596aa1
adds .zip support
go-while Oct 18, 2025
17b1436
debugs
go-while Oct 18, 2025
151e72a
debugs
go-while Oct 18, 2025
8ed4464
debugs
go-while Oct 18, 2025
0ac2658
debugs
go-while Oct 18, 2025
504e002
debugs
go-while Oct 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 21 additions & 122 deletions .github/workflows/build_and_publish_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
- name: "Set up Go"
uses: actions/setup-go@v5
with:
go-version: '1.25.1'
go-version: '1.25.3'
cache: false

# Install system dependencies based on runner OS
Expand Down Expand Up @@ -198,125 +198,21 @@ jobs:
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "GOOS=windows" >> $GITHUB_ENV

- name: "Build rapidyenc (macOS)"
if: matrix.os == 'darwin'
timeout-minutes: 5
run: |
cd rapidyenc
if [ "${{ matrix.arch }}" = "amd64" ]; then
./crossbuild_rapidyenc_darwin-amd64.sh || ./build_rapidyenc_linux-amd64.sh
else
# For arm64, we might need to build natively or cross-compile
./build_rapidyenc_linux-amd64.sh
fi

- name: "Build rapidyenc (Alpine/musl)"
if: matrix.libc == 'musl'
timeout-minutes: 5
run: |
cd rapidyenc && ./build_rapidyenc_linux-amd64.sh
# Note: May need Alpine-specific build script

# Run tests with race detector for supported platforms
- name: "Run race detector tests (amd64/linux only)"
if: matrix.os == 'linux' && matrix.arch == 'amd64' && !matrix.cross_compile
timeout-minutes: 5
run: go test -race ./rapidyenc/

- name: "Run normal tests (non-cross-compile platforms)"
if: ${{ !(matrix.cross_compile) && !(matrix.os == 'linux' && matrix.arch == 'amd64') }}
timeout-minutes: 5
run: go test ./rapidyenc/

- name: "Skip tests for cross-compiled platforms"
if: matrix.cross_compile
run: echo "Skipping tests for cross-compiled platform ${{ matrix.name }} (requires emulation or native hardware)"

- name: "Test rapidyenc integration"
if: ${{ !(matrix.cross_compile) }}
timeout-minutes: 2
run: |
# Build first if not cross-compiling
go build -o NZBreX -tags other .
./NZBreX -testrapidyenc
# - name: Clean Go module cache
# run: |
# rm -rf ~/.cache/go-build ~/go/pkg/mod
# - name: Restore Go modules cache
# # your cache restore step here

- name: "Set up Go"
uses: actions/setup-go@v5
with:
go-version: '1.24.3'
cache: true

#- name: Cache Go modules
# uses: actions/cache@v4
# with:
# path: |
# ~/.cache/go-build
# ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-

- name: "clone rapidyenc"
run: |
cd rapidyenc
if [ ! -e rapidyenc ]; then
./clone_rapidyenc.sh
if [ ! -e rapidyenc/.git ]; then
echo "rapidyenc/ src not found, exiting"
exit 1
fi
else
echo "rapidyenc/ src exists, skipping clone"
fi

# Build rapidyenc for different platforms
- name: "Build rapidyenc (Linux amd64)"
if: matrix.os == 'linux' && matrix.arch == 'amd64' && !matrix.cross_compile
timeout-minutes: 5
run: cd rapidyenc && ./build_rapidyenc_linux-amd64.sh

- name: "Build rapidyenc (Linux arm64 cross-compile)"
if: matrix.os == 'linux' && matrix.arch == 'arm64' && matrix.cross_compile
timeout-minutes: 5
run: |
cd rapidyenc && ./build_rapidyenc_linux-arm64.sh
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "GOARCH=arm64" >> $GITHUB_ENV

- name: "Build rapidyenc (Windows amd64 cross-compile)"
if: matrix.os == 'windows' && matrix.arch == 'amd64'
timeout-minutes: 5
run: |
cd rapidyenc && ./crossbuild_rapidyenc_windows-amd64.sh
echo "CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "GOOS=windows" >> $GITHUB_ENV

- name: "Build rapidyenc (macOS)"
if: matrix.os == 'darwin'
timeout-minutes: 5
run: |
cd rapidyenc
if [ "${{ matrix.arch }}" = "amd64" ]; then
./crossbuild_rapidyenc_darwin-amd64.sh || ./build_rapidyenc_linux-amd64.sh
else
# For arm64, we might need to build natively or cross-compile
./build_rapidyenc_linux-amd64.sh
fi

- name: "Build rapidyenc (Alpine/musl)"
if: matrix.libc == 'musl'
timeout-minutes: 5
run: |
cd rapidyenc && ./build_rapidyenc_linux-amd64.sh
# Note: May need Alpine-specific build script
# macOS builds natively - the build_rapidyenc_linux-amd64.sh script
# is actually a native build script (despite the misleading name)
./build_rapidyenc_linux-amd64.sh darwin

# Run tests with race detector for supported platforms
- name: "Run race detector tests (amd64/linux only)"
Expand Down Expand Up @@ -388,11 +284,14 @@ jobs:
mkdir -p builds/${{ matrix.name }}/usr/bin
if [ "${{ matrix.os }}" == "windows" ]; then
binary_name=NZBreX.exe
# For Windows: use static linking to avoid DLL dependencies
LDFLAGS="-X main.appVersion=${{ env.VERSION }} -linkmode external -extldflags '-static -static-libgcc -static-libstdc++'"
else
binary_name=NZBreX
LDFLAGS="-X main.appVersion=${{ env.VERSION }}"
fi
echo "BINARY=$binary_name" >> $GITHUB_ENV
GOARCH=${{ matrix.arch }} GOOS=${{ matrix.os }} go build -ldflags="-s -w -X main.appVersion=${{ env.VERSION }}" -o builds/${{ matrix.name }}/usr/bin/$binary_name
GOARCH=${{ matrix.arch }} GOOS=${{ matrix.os }} go build -ldflags="$LDFLAGS" -o builds/${{ matrix.name }}/usr/bin/$binary_name
if [ ! -f cleanHeaders.txt ]; then
echo "cleanHeaders.txt not found! Build cannot continue." >&2
exit 1
Expand All @@ -418,7 +317,7 @@ jobs:
cat builds/${{ matrix.name }}/usr/bin/$binary_name.sha512sum
fi
#
# packing the build
# packing the build (only create zip and deb for now)
#
# .zip
pwd && ls -lha && echo ".zip Packing builds/${{ matrix.name }}/usr/bin/$binary_name"
Expand All @@ -427,18 +326,18 @@ jobs:
LICENSE README.md rapidyenc/LICENSE rapidyenc/rapidyenc/README.md rapidyenc/rapidyenc/crcutil-1.0/LICENSE rapidyenc/rapidyenc/build/rapidyenc_* rapidyenc/rapidyenc/build/librapidyenc.*
#
# .tgz (tar + gzip)
pwd && ls -lha && echo ".tgz Packing builds/${{ matrix.name }}/usr/bin/$binary_name"
tar -czf "NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tgz" \
-C builds/${{ matrix.name }}/usr/bin $binary_name $binary_name.sha256sum $binary_name.sha512sum \
-C ${{ github.workspace }} cleanHeaders.txt provider.sample.json provider.ygg.json \
-C ${{ github.workspace }} LICENSE README.md rapidyenc/LICENSE rapidyenc/rapidyenc/README.md rapidyenc/rapidyenc/crcutil-1.0/LICENSE rapidyenc/rapidyenc/build/rapidyenc_* rapidyenc/rapidyenc/build/librapidyenc.*
#pwd && ls -lha && echo ".tgz Packing builds/${{ matrix.name }}/usr/bin/$binary_name"
#tar -czf "NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tgz" \
# -C builds/${{ matrix.name }}/usr/bin $binary_name $binary_name.sha256sum $binary_name.sha512sum \
# -C ${{ github.workspace }} cleanHeaders.txt provider.sample.json provider.ygg.json \
# -C ${{ github.workspace }} LICENSE README.md rapidyenc/LICENSE rapidyenc/rapidyenc/README.md rapidyenc/rapidyenc/crcutil-1.0/LICENSE rapidyenc/rapidyenc/build/rapidyenc_* rapidyenc/rapidyenc/build/librapidyenc.*
#
# .xz (tar + xz)
pwd && ls -lha && echo ".xz Packing builds/${{ matrix.name }}/usr/bin/$binary_name"
tar -cJf "NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tar.xz" \
-C builds/${{ matrix.name }}/usr/bin $binary_name $binary_name.sha256sum $binary_name.sha512sum \
-C ${{ github.workspace }} cleanHeaders.txt provider.sample.json provider.ygg.json \
-C ${{ github.workspace }} LICENSE README.md rapidyenc/LICENSE rapidyenc/rapidyenc/README.md rapidyenc/rapidyenc/crcutil-1.0/LICENSE rapidyenc/rapidyenc/build/rapidyenc_* rapidyenc/rapidyenc/build/librapidyenc.*
#pwd && ls -lha && echo ".xz Packing builds/${{ matrix.name }}/usr/bin/$binary_name"
#tar -cJf "NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tar.xz" \
# -C builds/${{ matrix.name }}/usr/bin $binary_name $binary_name.sha256sum $binary_name.sha512sum \
# -C ${{ github.workspace }} cleanHeaders.txt provider.sample.json provider.ygg.json \
# -C ${{ github.workspace }} LICENSE README.md rapidyenc/LICENSE rapidyenc/rapidyenc/README.md rapidyenc/rapidyenc/crcutil-1.0/LICENSE rapidyenc/rapidyenc/build/rapidyenc_* rapidyenc/rapidyenc/build/librapidyenc.*
#
# done packing
#
Expand Down Expand Up @@ -558,8 +457,8 @@ jobs:
prerelease: ${{ contains(env.VERSION, 'test') || contains(env.VERSION, 'beta') || contains(env.VERSION, 'alpha') }}
files: |
NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.deb
NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tgz
NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tar.xz
#NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tgz
#NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.tar.xz
NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.zip
NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.sha256sum
NZBreX_${{ env.VERSION }}-${{ env.SHA7 }}-${{ matrix.name }}${{ env.LIBC }}.sha512sum
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test*.*
*.pem
*.key
*.crt
.*passwd*

bak/*
log/
Expand Down
108 changes: 66 additions & 42 deletions Cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -156,19 +157,25 @@ func (c *Cache) GoCacheWriter(cid int) {
}
n := c.CacheWriter(item)
wrote_bytes += uint64(n)
// Memory slot already released by GoDownsRoutine before Add2Cache
}
} // end func c.GoCacheWriter

func (c *Cache) GoYencWriter(cid int) {
var wrote_bytes uint64
dlog(always, "GoYencWriter %d started", cid)
for {
dlog(cfg.opt.DebugCache, "GoYencWriter %d waiting for item...", cid)
yitem := <-c.yenc_writer_chan
if yitem == nil {
dlog(always, "YencWriter %d received nil item. closing. wrote total %d bytes", cid, wrote_bytes)
c.yenc_writer_chan <- nil
return
}
dlog(c.debug, "GoYencWriter %d processing seg.Id='%s'", cid, yitem.item.segment.Id)
n := c.YencWriter(yitem)
wrote_bytes += uint64(n)
dlog(c.debug, "GoYencWriter %d finished seg.Id='%s' wrote=%d bytes", cid, yitem.item.segment.Id, n)
}
} // end func c.GoCacheWriter

Expand Down Expand Up @@ -295,20 +302,31 @@ func (c *Cache) WriteYenc(item *segmentChanItem, yPart *yenc.Part) {
dlog(always, "ERROR WriteYenc: empty Body seg.Id='%s'", item.segment.Id)
return
}
GCounter.Incr("yencQueueCnt")
GCounter.Incr("TOTAL_yencQueueCnt")

// Set flag BEFORE incrementing counter to avoid race
item.mux.Lock()
item.flaginYenc = true
item.mux.Unlock()
c.yenc_writer_chan <- &yenc_item{
item: item,
yPart: yPart,

wait:
for {
select {
case c.yenc_writer_chan <- &yenc_item{item: item, yPart: yPart}: // enqueue
// Increment counter AFTER successful enqueue
GCounter.Incr("yencQueueCnt")
GCounter.Incr("TOTAL_yencQueueCnt")
break wait
default:
// chan full
log.Printf("WriteYenc waiting to enqueue seg.Id='%s' yenc_queue_cnt=%d channel=%d/%d", item.segment.Id, GCounter.GetValue("yencQueueCnt"), len(c.yenc_writer_chan), cap(c.yenc_writer_chan))
time.Sleep(time.Second)
}
}
} // emd func WriteYenc

func (c *Cache) YencWriter(yitem *yenc_item) (wrote_bytes int) {
defer GCounter.Decr("yencQueueCnt")

dlog(always, "YencWriter processing seg.Id='%s'", yitem.item.segment.Id)
yitem.item.mux.Lock()
if yitem.item.hashedId == "" {
yitem.item.hashedId = SHA256str("<" + yitem.item.segment.Id + ">")
Expand All @@ -318,53 +336,59 @@ func (c *Cache) YencWriter(yitem *yenc_item) (wrote_bytes int) {
_, _, yencdir, fp, fp_tmp := c.GetYenc(yitem.item)

if FileExists(fp) {
c.resetYencFlagsOnErr(yitem.item)
dlog(c.debug, "YencWriter file already exists, skipping: '%s'", fp)
yitem.item.mux.Lock()
yitem.item.flaginYenc = false
yitem.item.flagisYenc = true // File exists, so yenc IS done
yitem.item.mux.Unlock()
return 0
}

if !Mkdir(yencdir) {
dlog(always, "ERROR YencWriter Mkdir failed dir='%s'", yencdir)
c.resetYencFlagsOnErr(yitem.item)
return 0
}

dlog(c.debug, "Writing yenc part: '%s'", fp_tmp)
if file, err := os.OpenFile(fp_tmp, os.O_CREATE|os.O_WRONLY, 0644); err == nil {
defer func() {
if cerr := file.Close(); cerr != nil {
dlog(always, "ERROR YencWriter file.Close err='%v'", cerr)
}
}()
datawriter := bufio.NewWriterSize(file, DefaultYencWriteBuffer)
if n, err := datawriter.Write(yitem.yPart.Body); err != nil {
dlog(always, "ERROR YencWriter datawriter.Write err='%v'", err)
c.resetYencFlagsOnErr(yitem.item)
return 0
} else {
wrote_bytes += n
}
dlog(always, "DEBUG: Writing yenc part: '%s'", fp_tmp)
file, err := os.OpenFile(fp_tmp, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
dlog(always, "ERROR YencWriter OpenFile failed fp_tmp='%s' err='%v'", fp_tmp, err)
c.resetYencFlagsOnErr(yitem.item)
return 0
}

if err := datawriter.Flush(); err != nil {
dlog(always, "ERROR YencWriter datawriter.Flush err='%v'", err)
c.resetYencFlagsOnErr(yitem.item)
return 0
}
datawriter := bufio.NewWriterSize(file, DefaultYencWriteBuffer)
if n, err := datawriter.Write(yitem.yPart.Body); err != nil {
dlog(always, "ERROR YencWriter datawriter.Write err='%v'", err)
c.resetYencFlagsOnErr(yitem.item)
return 0
} else {
wrote_bytes += n
}

if err := os.Rename(fp_tmp, fp); err != nil {
dlog(always, "ERROR YencWriter move .tmp failed err='%v'", err)
c.resetYencFlagsOnErr(yitem.item)
return 0
}
if err := datawriter.Flush(); err != nil {
dlog(always, "ERROR YencWriter datawriter.Flush err='%v'", err)
c.resetYencFlagsOnErr(yitem.item)
return 0
}

yitem.item.mux.Lock()
yitem.item.flaginYenc = false
yitem.item.flagisYenc = true
/* // watch out for broken wings #99ffff!
if yitem.item.flaginUP {
doMemReturn = false
}
*/
yitem.item.mux.Unlock()
} // end OpenFile
if err := os.Rename(fp_tmp, fp); err != nil {
dlog(always, "ERROR YencWriter move .tmp failed err='%v'", err)
c.resetYencFlagsOnErr(yitem.item)
return 0
}

if err := file.Close(); err != nil {
dlog(always, "ERROR YencWriter file.Close err='%v'", err)
c.resetYencFlagsOnErr(yitem.item)
return 0
}

yitem.item.mux.Lock()
yitem.item.flaginYenc = false
yitem.item.flagisYenc = true
yitem.item.mux.Unlock()
yitem.yPart.Body = nil
yitem.yPart = nil
return
Expand Down
Loading
Loading