mirror of
https://github.com/mtheall/ftpd.git
synced 2025-06-18 11:05:52 -04:00
Apply timezone offset from rosalina's ntp feature
This commit is contained in:
parent
30f4a21d17
commit
ddadc52fe4
@ -63,6 +63,11 @@ public:
|
||||
/// \brief Server start time
|
||||
static std::time_t startTime ();
|
||||
|
||||
#ifdef __3DS__
|
||||
/// \brief Get timezone offset in seconds (only used on 3DS)
|
||||
static int tzOffset ();
|
||||
#endif
|
||||
|
||||
private:
|
||||
/// \brief Paramterized constructor
|
||||
/// \param config_ FTP config
|
||||
|
@ -26,7 +26,10 @@
|
||||
#include "platform.h"
|
||||
#include "socket.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
@ -159,6 +162,16 @@ private:
|
||||
/// \brief Connect data socket
|
||||
bool dataConnect ();
|
||||
|
||||
/// \brief Perform stat and apply tz offset to mtime
|
||||
/// \param path_ Path to stat
|
||||
/// \param st_ Output stat
|
||||
int tzStat (char const *const path_, struct stat *st_);
|
||||
|
||||
/// \brief Perform lstat and apply tz offset to mtime
|
||||
/// \param path_ Path to lstat
|
||||
/// \param st_ Output stat
|
||||
int tzLStat (char const *const path_, struct stat *st_);
|
||||
|
||||
/// \brief Fill directory entry
|
||||
/// \param st_ Entry status
|
||||
/// \param path_ Path name
|
||||
@ -291,7 +304,7 @@ private:
|
||||
/// \brief Directory transfer mode
|
||||
XferDirMode m_xferDirMode;
|
||||
|
||||
/// \brief Last command timestamp
|
||||
/// \brief Last activity timestamp
|
||||
time_t m_timestamp;
|
||||
|
||||
/// \brief Whether user has been authorized
|
||||
|
@ -66,6 +66,11 @@ namespace
|
||||
/// \brief Application start time
|
||||
auto const s_startTime = std::time (nullptr);
|
||||
|
||||
#ifdef __3DS__
|
||||
/// \brief Timezone offset in seconds (only used on 3DS)
|
||||
int s_tzOffset = 0;
|
||||
#endif
|
||||
|
||||
#ifndef __NDS__
|
||||
/// \brief Mutex for s_freeSpace
|
||||
platform::Mutex s_lock;
|
||||
@ -190,6 +195,12 @@ FtpServer::FtpServer (UniqueFtpConfig config_) : m_config (std::move (config_)),
|
||||
#ifndef __NDS__
|
||||
m_thread = platform::Thread (std::bind (&FtpServer::threadFunc, this));
|
||||
#endif
|
||||
|
||||
#ifdef __3DS__
|
||||
s64 tzOffsetMinutes;
|
||||
if (R_SUCCEEDED (svcGetSystemInfo (&tzOffsetMinutes, 0x10000, 0x103)))
|
||||
s_tzOffset = tzOffsetMinutes * 60;
|
||||
#endif
|
||||
}
|
||||
|
||||
void FtpServer::draw ()
|
||||
@ -372,6 +383,13 @@ std::time_t FtpServer::startTime ()
|
||||
return s_startTime;
|
||||
}
|
||||
|
||||
#ifdef __3DS__
|
||||
int FtpServer::tzOffset ()
|
||||
{
|
||||
return s_tzOffset;
|
||||
}
|
||||
#endif
|
||||
|
||||
void FtpServer::handleNetworkFound ()
|
||||
{
|
||||
SockAddr addr;
|
||||
@ -869,7 +887,8 @@ void FtpServer::loop ()
|
||||
{
|
||||
auto const key = json_object_get (root, "key");
|
||||
if (json_is_string (key))
|
||||
info ("Log uploaded to https://pastie.io/%s\n", json_string_value (key));
|
||||
info (
|
||||
"Log uploaded to https://pastie.io/%s\n", json_string_value (key));
|
||||
}
|
||||
else
|
||||
error ("Failed to upload log\n");
|
||||
|
@ -739,7 +739,7 @@ bool FtpSession::changeDir (char const *const args_)
|
||||
return false;
|
||||
|
||||
struct stat st;
|
||||
if (::stat (path.c_str (), &st) != 0)
|
||||
if (tzStat (path.c_str (), &st) != 0)
|
||||
return false;
|
||||
|
||||
if (!S_ISDIR (st.st_mode))
|
||||
@ -821,6 +821,48 @@ bool FtpSession::dataConnect ()
|
||||
return true;
|
||||
}
|
||||
|
||||
int FtpSession::tzStat (char const *const path_, struct stat *st_)
|
||||
{
|
||||
auto const rc = ::stat (path_, st_);
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
#ifdef __3DS__
|
||||
if (m_config.getMTime ())
|
||||
{
|
||||
std::uint64_t mtime = 0;
|
||||
auto const rc = archive_getmtime (path_, &mtime);
|
||||
if (rc != 0)
|
||||
error ("sdmc_getmtime %s 0x%lx\n", path_, rc);
|
||||
else
|
||||
st_->st_mtime = mtime - FtpServer::tzOffset ();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FtpSession::tzLStat (char const *const path_, struct stat *st_)
|
||||
{
|
||||
auto const rc = ::lstat (path_, st_);
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
#ifdef __3DS__
|
||||
if (m_config.getMTime ())
|
||||
{
|
||||
std::uint64_t mtime = 0;
|
||||
auto const rc = archive_getmtime (path_, &mtime);
|
||||
if (rc != 0)
|
||||
error ("sdmc_getmtime %s 0x%lx\n", path_, rc);
|
||||
else
|
||||
st_->st_mtime = mtime - FtpServer::tzOffset ();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FtpSession::fillDirent (struct stat const &st_, std::string_view const path_, char const *type_)
|
||||
{
|
||||
auto const buffer = m_xferBuffer.freeArea ();
|
||||
@ -1108,7 +1150,7 @@ int FtpSession::fillDirent (struct stat const &st_, std::string_view const path_
|
||||
int FtpSession::fillDirent (std::string const &path_, char const *type_)
|
||||
{
|
||||
struct stat st;
|
||||
if (::stat (path_.c_str (), &st) != 0)
|
||||
if (tzStat (path_.c_str (), &st) != 0)
|
||||
return errno;
|
||||
|
||||
return fillDirent (st, encodePath (path_), type_);
|
||||
@ -1135,7 +1177,7 @@ void FtpSession::xferFile (char const *const args_, XferFileMode const mode_)
|
||||
{
|
||||
// stat the file
|
||||
struct stat st;
|
||||
if (::stat (path.c_str (), &st) != 0)
|
||||
if (tzStat (path.c_str (), &st) != 0)
|
||||
{
|
||||
sendResponse ("450 %s\r\n", std::strerror (errno));
|
||||
return;
|
||||
@ -1267,7 +1309,7 @@ void FtpSession::xferDir (char const *const args_, XferDirMode const mode_, bool
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if (::stat (path.c_str (), &st) != 0)
|
||||
if (tzStat (path.c_str (), &st) != 0)
|
||||
{
|
||||
if (needWorkaround)
|
||||
{
|
||||
@ -1767,14 +1809,14 @@ bool FtpSession::listTransfer ()
|
||||
if (rc != 0)
|
||||
error ("sdmc_getmtime %s 0x%lx\n", fullPath.c_str (), rc);
|
||||
else
|
||||
st.st_mtime = mtime;
|
||||
st.st_mtime = mtime - FtpServer::tzOffset ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
// lstat the entry
|
||||
if (::lstat (fullPath.c_str (), &st) != 0)
|
||||
if (tzLStat (fullPath.c_str (), &st) != 0)
|
||||
{
|
||||
error ("Skipping %s: %s\n", fullPath.c_str (), std::strerror (errno));
|
||||
continue; // just skip it
|
||||
@ -2556,7 +2598,7 @@ void FtpSession::RNFR (char const *args_)
|
||||
|
||||
// make sure the path exists
|
||||
struct stat st;
|
||||
if (::lstat (path.c_str (), &st) != 0)
|
||||
if (tzLStat (path.c_str (), &st) != 0)
|
||||
{
|
||||
sendResponse ("450 %s\r\n", std::strerror (errno));
|
||||
return;
|
||||
@ -2751,7 +2793,7 @@ void FtpSession::SIZE (char const *args_)
|
||||
|
||||
// stat the path
|
||||
struct stat st;
|
||||
if (::stat (path.c_str (), &st) != 0)
|
||||
if (tzStat (path.c_str (), &st) != 0)
|
||||
{
|
||||
sendResponse ("550 %s\r\n", std::strerror (errno));
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user