Skip to content

Commit

Permalink
Fix tile dumping when /tmp is not temporary directory
Browse files Browse the repository at this point in the history
On iOS, each app has its own sandbox which has a temporary directory.
The FileUtil::getSysTempDirectoryPath() method successfully gets this
directory and we create a tiledump directory under it. Sadly, we then
try to write to /tmp regardless of where the temporary directory is.

This commit makes us also write our file in the directory returned by
FileUtil::getSysTempDirectoryPath()

Signed-off-by: Skyler Grey <[email protected]>
Change-Id: Ic8425cb94d1d85ac9c77212eb84d0ca7c46cd34e
  • Loading branch information
Minion3665 committed Oct 9, 2023
1 parent 5520965 commit e13a251
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions kit/Delta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,45 +734,40 @@ class DeltaGenerator {
int dumpedIndex = 1;
if (dumpTiles)
{
std::string path = "/tmp/tiledump";
bool directoryExists = !FileUtil::isEmptyDirectory(path);
std::string path = FileUtil::getSysTempDirectoryPath() + "/tiledump";
bool directoryExists = FileUtil::Stat(path).exists();
if (!directoryExists)
{
FileUtil::createTmpDir("tiledump");
directoryExists = true;
}
if (directoryExists)
{
// filename format: tile-<viewid>-<part>-<left>-<top>-<index>.png
std::ostringstream oss;
oss << "tile-" << loc._canonicalViewId << "-" << loc._part << "-" << loc._left << "-" << loc._top << "-";
std::string baseFilename = oss.str();

// find the next available filename
bool found = false;
int index = 1;
// filename format: tile-<viewid>-<part>-<left>-<top>-<index>.png
std::ostringstream oss;
oss << "tile-" << loc._canonicalViewId << "-" << loc._part << "-" << loc._left << "-" << loc._top << "-";
std::string baseFilename = oss.str();

// find the next available filename
bool found = false;
int index = 1;

while (!found)
while (!found)
{
std::string filename = std::string("/") + baseFilename + std::to_string(index) + ".png";
if (!FileUtil::Stat(path + filename).exists())
{
std::string filename = std::string("/") + baseFilename + std::to_string(index) + ".png";
if (!FileUtil::Stat(path + filename).exists())
{
found = true;
path += filename;
dumpedIndex = index;
}
else
{
index++;
}
found = true;
path += filename;
dumpedIndex = index;
}
else
{
index++;
}

std::ofstream tileFile(path, std::ios::binary);
std::vector<char> pngOutput;
Png::encodeSubBufferToPNG(pixmap, startX, startY, width, height,
bufferWidth, bufferHeight, pngOutput, mode);
tileFile.write(pngOutput.data(), pngOutput.size());
}

std::ofstream tileFile(path, std::ios::binary);
std::vector<char> pngOutput;
Png::encodeSubBufferToPNG(pixmap, startX, startY, width, height,
bufferWidth, bufferHeight, pngOutput, mode);
tileFile.write(pngOutput.data(), pngOutput.size());
}

if (!createDelta(pixmap, startX, startY, width, height,
Expand Down Expand Up @@ -839,7 +834,7 @@ class DeltaGenerator {
// Dump the delta
if (dumpTiles)
{
std::string path = "/tmp/tiledump";
std::string path = FileUtil::getSysTempDirectoryPath() + "tiledump";
std::ostringstream oss;
// filename format: tile-delta-<viewid>-<part>-<left>-<top>-<prev_index>_to_<index>.zstd
oss << "tile-delta-" << loc._canonicalViewId << "-" << loc._part << "-" << loc._left << "-" << loc._top
Expand Down

0 comments on commit e13a251

Please sign in to comment.