Skip to content

Commit

Permalink
temporary changes for esp8266
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Jan 23, 2025
1 parent 4bf7fed commit 09d0517
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 46 deletions.
14 changes: 7 additions & 7 deletions src/ESP32-targz-lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
#define FS_NAME "SPIFFS"
#endif
#else // no destination filesystem defined in sketch
#warning "Unspecified or invalid destination filesystem, please #define one of these before including the library: DEST_FS_USES_SPIFFS, DEST_FS_USES_LITTLEFS, DEST_FS_USES_SD, DEST_FS_USES_PSRAMFS"
// #warning "Unspecified or invalid destination filesystem, please #define one of these before including the library: DEST_FS_USES_SPIFFS, DEST_FS_USES_LITTLEFS, DEST_FS_USES_SD, DEST_FS_USES_PSRAMFS"
// however, check for USE_LittleFS as it is commonly defined since SPIFFS deprecation
#if defined USE_LittleFS
#include <LittleFS.h>
Expand Down Expand Up @@ -164,6 +164,7 @@

#endif


#if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_FFAT
#define WARN_LIMITED_FS
#endif
Expand Down Expand Up @@ -243,6 +244,11 @@ typedef void (*genericProgressCallback)(uint8_t progress); // percent (0...100)
typedef void (*genericLoggerCallback)( const char* format, ... ); // same behaviour as printf()


// md5sum (essentially for debug)
#include "helpers/md5_sum.h"
// helpers: mkdir, mkpath, dirname
#include "helpers/path_tools.h"

#if !defined ESP32_TARGZ_DISABLE_DECOMPRESSION
#include "libunpacker/LibUnpacker.hpp"
#else
Expand All @@ -257,10 +263,4 @@ typedef void (*genericLoggerCallback)( const char* format, ... ); // same behavi
#endif


// md5sum (essentially for debug)
#include "helpers/md5_sum.h"
// helpers: mkdir, mkpath, dirname
#include "helpers/path_tools.h"


//#endif // #ifdef _ESP_TGZ_H
17 changes: 9 additions & 8 deletions src/ESP32-targz-log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#pragma once

inline void NullLoggerCallback( [[maybe_unused]] const char* format, ...) { yield(); }

#if defined ESP8266 || defined ESP32
// those have OTA and common device API
Expand All @@ -57,22 +58,22 @@
#if defined DEBUG_ESP_VERBOSE
#define log_v(format, ...) DEBUG_ESP_PORT.printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__);
#else
#define log_v(format, ...) BaseUnpacker::targzNullLoggerCallback
#define log_v(format, ...) NullLoggerCallback
#endif
#else
// don't be verbose, only errors+warnings
#define log_i BaseUnpacker::targzNullLoggerCallback
#define log_d BaseUnpacker::targzNullLoggerCallback
#define log_v BaseUnpacker::targzNullLoggerCallback
#define log_i NullLoggerCallback
#define log_d NullLoggerCallback
#define log_v NullLoggerCallback
#endif

#else
#define log_n(format, ...) Serial.printf(ARDUHAL_LOG_FORMAT(N, format), ##__VA_ARGS__);
#define log_e(format, ...) Serial.printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__);
#define log_w BaseUnpacker::targzNullLoggerCallback
#define log_i BaseUnpacker::targzNullLoggerCallback
#define log_d BaseUnpacker::targzNullLoggerCallback
#define log_v BaseUnpacker::targzNullLoggerCallback
#define log_w NullLoggerCallback
#define log_i NullLoggerCallback
#define log_d NullLoggerCallback
#define log_v NullLoggerCallback
#endif

#else
Expand Down
4 changes: 1 addition & 3 deletions src/libpacker/LibPacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ namespace TarPacker
return -1;
}
log_v("stat_func: stating %s", path );
fs::File f = fs->open(path);
fs::File f = fs->open(path, "r");

if(!f) {
log_e("Unable to open %s for stat", path);
Expand Down Expand Up @@ -897,8 +897,6 @@ namespace TarGzPacker
while(1) yield();
}



log_d("Stream to Stream mode enabled");

// for lambda capture
Expand Down
2 changes: 1 addition & 1 deletion src/libpacker/LibPacker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace TarGzPacker
virtual void flush() { };
// Print methods (not used in this implementation)
virtual void end() { };
virtual size_t write(uint8_t c) { return 0; };
virtual size_t write(uint8_t c) { return c?0:0; };
};

// tar gz methods
Expand Down
21 changes: 15 additions & 6 deletions src/libpacker/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace TAR

tar_files_packer_t *p{nullptr};;
std::vector<dir_entity_t> *dirEntities{nullptr};
int iterator{0};
size_t iterator{0};
dir_entity_t dirEntity{"",false,0}; // last parsed entity
entity_t entity{ nullptr, nullptr, nullptr, nullptr, ENTITY_STAT, 0 };
String SavePath{""};
Expand Down Expand Up @@ -111,7 +111,7 @@ namespace TAR
assert(fs);
assert(dirname);

File root = fs->open(dirname);
File root = fs->open(dirname, "r");
if (!root) {
log_e("Failed to open directory %s", dirname);
return;
Expand All @@ -120,20 +120,29 @@ namespace TAR
log_e("Not a directory %s", dirname);
return;
}
log_v(" DIR: %-16s", dirname);
//log_v(" DIR: %-16s", dirname);

dirEntities->push_back( { String(dirname), true, 0 } );

File file = root.openNextFile();

while (file) {
const char* file_path =
#if defined ESP32 || defined ARDUINO_ARCH_RP2040
file.path()
#elif defined ESP8266
file.fullName()
#else
#error
#endif
;
if (file.isDirectory()) {
if (levels) {
collectDirEntities(dirEntities, fs, file.path(), levels - 1);
collectDirEntities(dirEntities, fs, file_path, levels - 1);
}
} else {
dirEntities->push_back( { String(file.path()), false, file.size() } );
log_v(" FILE: %-16s\tSIZE: %6d", file.name(), file.size() );
dirEntities->push_back( { String(file_path), false, file.size() } );
//log_v(" FILE: %-16s\tSIZE: %6d", file.name(), file.size() );
}
file = root.openNextFile();
}
Expand Down
1 change: 0 additions & 1 deletion src/libunpacker/LibUnpacker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#include "../ESP32-targz-lib.hpp"


namespace TAR
{
#include "../TinyUntar/untar.h"
Expand Down
39 changes: 19 additions & 20 deletions src/tar/libtar.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <ctype.h> // for isprint()


#include "../ESP32-targz-log.hpp" // import log_e(), log_w(), log_d() and log_i(), all behaving like printf()
// #include "../ESP32-targz-log.hpp" // import log_e(), log_w(), log_d() and log_i(), all behaving like printf()

#define UID "root"
#define GID "root"
Expand All @@ -53,7 +53,7 @@ char * tar_block;
int tar_init(TAR *t, const char *pathname, tar_callback_t *io, void *opaque)
{
if (t == NULL) {
log_e("Failed to alloc %d files for tar", sizeof(TAR));
//log_e("Failed to alloc %d files for tar", sizeof(TAR));
return -1;
}

Expand All @@ -63,16 +63,16 @@ int tar_init(TAR *t, const char *pathname, tar_callback_t *io, void *opaque)

tar_block = (char*)calloc(1, T_BLOCKSIZE);
if( tar_block==NULL ) {
log_e("Failed to alloc %d files for tar_block", sizeof(TAR));
//log_e("Failed to alloc %d files for tar_block", sizeof(TAR));
return -1;
}

if( io==NULL ){
log_e("No attached callbacks");
//log_e("No attached callbacks");
return -1;
}

log_d("Tar init done");
//log_d("Tar init done");

return 0;
}
Expand All @@ -82,11 +82,10 @@ int tar_open(TAR *t, const char *pathname, tar_callback_t *io, const char *mode,
{
if (tar_init(t, pathname, io, opaque) == -1)
return -1;
log_d("Tar open %s with '%s' flag", pathname, mode);
//log_d("Tar open %s with '%s' flag", pathname, mode);
t->fd = (*(t->io->openfunc))(t->opaque, pathname, mode);
if (t->fd == (void *)-1) {
log_e("Failed to open file %s with %s flag", pathname, mode);
// free(*t);
//log_e("Failed to open file %s with %s flag", pathname, mode);
return -1;
}
return 0;
Expand Down Expand Up @@ -158,7 +157,7 @@ int tar_append_entity_step(entity_t *e)
th_set_path(e->tar, (e->savename ? e->savename : e->realname)); // set the header path
e->step = ENTITY_HEADER;
// fallthrough
case ENTITY_HEADER: log_d("Entity header(%s)", e->realname);
case ENTITY_HEADER: //log_d("Entity header(%s)", e->realname);
if (th_write(e->tar, e->written_bytes) != 0) { // header write failed?
return -1;
}
Expand Down Expand Up @@ -216,14 +215,14 @@ int tar_append_eof(TAR *t, ssize_t *written_bytes)
if (i != T_BLOCKSIZE) {
if (i != -1)
errno = EINVAL;
log_e("written bytes (%d) don't match tar block size (%d)", i, T_BLOCKSIZE);
//log_e("written bytes (%d) don't match tar block size (%d)", i, T_BLOCKSIZE);
return -1;
}
}
// trigger last write signal (reminder: writefunc may be async)
if( t->io->closewritefunc(t->opaque, t->fd) == -1 )
return -1;
log_v("Wrote %d leftover bytes", leftover_bytes);
//log_v("Wrote %d leftover bytes", leftover_bytes);
return 0;
}

Expand All @@ -242,19 +241,19 @@ int tar_append_regfile_step(TAR *t, const char *realname, ssize_t *written_bytes
case OPEN_FILE:
regfile_iterator = 0;
regfile_rv = -1;
log_d("Adding %s", realname);
//log_d("Adding %s", realname);
regfile_fd = t->io->openfunc(t->opaque, realname, "r");
if (regfile_fd == (void *)-1)
return -1;
regfile_size = (unsigned int)oct_to_int((t)->th_buf.size);
memset(tar_block, 0, T_BLOCKSIZE);
regfile_iterator = regfile_size;
log_v("Assigning size (%d)", regfile_size);
//log_v("Assigning size (%d)", regfile_size);
regfile_step = WRITE_BLOCK;
// fallthrough
case WRITE_BLOCK:
{
log_v("WRITE_BLOCK");
//log_v("WRITE_BLOCK");
if(regfile_iterator <= T_BLOCKSIZE ) {
regfile_step = WRITE_LAST_BLOCK;
return 0;
Expand All @@ -273,13 +272,13 @@ int tar_append_regfile_step(TAR *t, const char *realname, ssize_t *written_bytes
return 0;
}
regfile_iterator -= block_size;
log_v("Wrote %lu bytes, regfile_iterator=%d", T_BLOCKSIZE, regfile_iterator);
//log_v("Wrote %lu bytes, regfile_iterator=%d", T_BLOCKSIZE, regfile_iterator);
*written_bytes += block_size;
}
break;
case WRITE_LAST_BLOCK:
{
log_v("case WRITE_LAST_BLOCK");
//log_v("case WRITE_LAST_BLOCK");
regfile_step = CLOSE_FILE;
if (regfile_iterator > 0) {
regfile_read_bytes = t->io->readfunc(t->opaque, regfile_fd, tar_block, regfile_iterator);
Expand All @@ -291,14 +290,14 @@ int tar_append_regfile_step(TAR *t, const char *realname, ssize_t *written_bytes
if ( block_size == -1) {
return 0;
}
log_v("Wrote %lu last bytes", T_BLOCKSIZE);
//log_v("Wrote %lu last bytes", T_BLOCKSIZE);
*written_bytes += block_size;
}
}
regfile_rv = 0;
// fallthrough
case CLOSE_FILE:
log_v("case CLOSE_FILE");
//log_v("case CLOSE_FILE");
t->io->closefunc(t->opaque, regfile_fd);
regfile_fd = NULL;
return regfile_rv;
Expand Down Expand Up @@ -334,7 +333,7 @@ int th_write(TAR *t, ssize_t *written_bytes)

i = t->io->writefunc(t->opaque, (t)->fd, &(t->th_buf), T_BLOCKSIZE);
if (i != T_BLOCKSIZE) {
log_e("ERROR in th_write, returned block size %d didn't match expexted size %d", i, (int)T_BLOCKSIZE);
//log_e("ERROR in th_write, returned block size %d didn't match expexted size %d", i, (int)T_BLOCKSIZE);
if (i != -1) {
errno = EINVAL;
}
Expand Down Expand Up @@ -376,7 +375,7 @@ void th_set_path(TAR *t, const char *pathname)
// POSIX-style prefix field
tmp = (char *)strchr(&(pathname[strlen(pathname) - T_NAMELEN - 1]), '/');
if (tmp == NULL) {
log_e("ERROR: no '/' found in \"%s\"", pathname);
//log_e("ERROR: no '/' found in \"%s\"", pathname);
return;
}
snprintf(t->th_buf.name, 100, "%s%s", &(tmp[1]), suffix);
Expand Down

0 comments on commit 09d0517

Please sign in to comment.