Skip to content

Commit

Permalink
backport save2flash bug fixes from 11.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Oct 5, 2024
1 parent 5dd4a98 commit d6ed224
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 8 additions & 7 deletions woof-code/rootfs-petbuilds/psnapcp/psnapcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

int main(int argc, char *argv[])
{
int src, dst;
int src, dst, sync = 0;
struct stat srcstat, dststat;
struct timeval times[2];
unsigned char *srcm, *dstm;
Expand Down Expand Up @@ -47,9 +47,6 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}

if (dststat.st_size == srcstat.st_size && dststat.st_mtime >= srcstat.st_mtime)
goto meta;

if (dststat.st_size != srcstat.st_size && ftruncate(dst, srcstat.st_size) < 0) {
fprintf(stderr, "Failed to set %s size: %s\n", argv[2], strerror(errno));
close(dst);
Expand Down Expand Up @@ -78,22 +75,26 @@ int main(int argc, char *argv[])
madvise(srcm, srcstat.st_size, MADV_SEQUENTIAL);
madvise(dstm, srcstat.st_size, MADV_SEQUENTIAL);

if (srcstat.st_size > 0 && dststat.st_size == 0)
if (srcstat.st_size > 0 && dststat.st_size == 0) {
memcpy(dstm, srcm, srcstat.st_size);
sync = 1;
}
else {
do {
chunk = srcstat.st_size - off >= CHUNK_SIZE ? CHUNK_SIZE : srcstat.st_size - off;

if (memcmp(&srcm[off], &dstm[off], chunk) != 0)
if (memcmp(&srcm[off], &dstm[off], chunk) != 0) {
memcpy(&dstm[off], &srcm[off], chunk);
sync = 1;
}

off += chunk;
} while (off < srcstat.st_size);
}

munmap(srcm, srcstat.st_size);

if (msync(dstm, srcstat.st_size, MS_SYNC) < 0) {
if (sync && msync(dstm, srcstat.st_size, MS_SYNC) < 0) {
fprintf(stderr, "Failed to flush changes to disk: %s\n", strerror(errno));
munmap(dstm, srcstat.st_size);
close(dst);
Expand Down
11 changes: 9 additions & 2 deletions woof-code/rootfs-skeleton/usr/sbin/snapmergepuppy.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,15 @@ while read -r N
do
#v4.01 graceful exit if shutdown X (see /usr/X11R7/bin/restartwm,wmreboot,wmpoweroff)...
[ "$XRUNNING" = "yes" ] && [ -f /tmp/wmexitmode.txt ] && exit
rm -f "$BASE/$N" 2>/dev/null
mkdir -p "$BASE/$N"
if [ -L "$BASE/$N" ];then
rm -f "$BASE/$N" 2>/dev/null
mkdir "$BASE/$N"
elif [ ! -e "$BASE/$N" ];then
mkdir "$BASE/$N"
elif [ ! -d "$BASE/$N" ];then
rm -f "$BASE/$N" 2>/dev/null
mkdir "$BASE/$N"
fi
#i think nathan advised this, to handle non-root user (SFR: improved/simplified)
chmod "$BASE/$N" --reference="$N"
chown-FULL "$BASE/$N" --reference="$N"
Expand Down

0 comments on commit d6ed224

Please sign in to comment.