Skip to content

Commit

Permalink
Change DDF bundle file extension to .ddb (#7813)
Browse files Browse the repository at this point in the history
Previously it was .ddf but confused users since in the UI raw JSON DDF are shown with DDF label and bundles with DDB label.

The code still supports loading .ddf. New uploaded bundles get .ddb file extension.
  • Loading branch information
manup authored Jun 14, 2024
1 parent a5889ca commit 516045b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion device_descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,7 @@ void DeviceDescriptions::readAllBundles()

U_sstream_init(&ss, dir.entry.name, strlen(dir.entry.name));

if (U_sstream_find(&ss, ".ddf") == 0)
if (U_sstream_find(&ss, ".ddf") == 0 && U_sstream_find(&ss, ".ddb") == 0)
continue;

ScratchMemRewind(scratchPosPerBundle);
Expand Down
32 changes: 27 additions & 5 deletions rest_ddf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static unsigned char *BinToHexAscii(const void *hex, unsigned length, void *asci
Test upload of .ddf file
curl -F 'data=@/home/mpi/some.ddf' 127.0.0.1:8090/api/12345/ddf
curl -F 'data=@/home/mpi/some.ddb' 127.0.0.1:8090/api/12345/ddf
*/

Expand Down Expand Up @@ -253,7 +253,7 @@ int REST_DDF_GetDescriptors(const ApiRequest &req, ApiResponse &rsp)

U_sstream_init(&ss, dir.entry.name, strlen(dir.entry.name));

if (U_sstream_find(&ss, ".ddf") == 0)
if (U_sstream_find(&ss, ".ddf") == 0 && U_sstream_find(&ss, ".ddb") == 0)
continue;

if (curCursor < reqCursor)
Expand Down Expand Up @@ -358,7 +358,7 @@ int REST_DDF_GetBundle(const ApiRequest &req, ApiResponse &rsp)
U_SStream ssFileName;
U_sstream_init(&ssFileName, fileName, maxFileNameLength);
U_sstream_put_str(&ssFileName, bundleHashStr);
U_sstream_put_str(&ssFileName, ".ddf");
U_sstream_put_str(&ssFileName, ".ddb");
}

deCONZ::StorageLocation locations[2] = { deCONZ::DdfBundleUserLocation, deCONZ::DdfBundleLocation };
Expand All @@ -382,7 +382,7 @@ int REST_DDF_GetBundle(const ApiRequest &req, ApiResponse &rsp)

U_sstream_init(&ss, dir.entry.name, strlen(dir.entry.name));

if (U_sstream_find(&ss, ".ddf") == 0)
if (U_sstream_find(&ss, ".ddf") == 0 && U_sstream_find(&ss, ".ddb") == 0)
continue;

U_sstream_init(&ss, path, MAX_PATH_LENGTH);
Expand Down Expand Up @@ -449,7 +449,7 @@ int REST_DDF_PostBundles(const ApiRequest &req, ApiResponse &rsp)
const QVariantMap errServiceNotAvailable = errorToMap(ERR_INTERNAL_ERROR, "/ddf/bundles", "Internal error, can't process request");

// TEST call
// curl -F 'data=@./starkvind_air_purifier_toolbox.ddf' 127.0.0.1:8090/api/12345/ddf/bundles
// curl -F 'data=@./starkvind_air_purifier_toolbox.ddb' 127.0.0.1:8090/api/12345/ddf/bundles

if (req.hdr.contentLength() < 32 || req.hdr.contentLength() > 512000)
{
Expand Down Expand Up @@ -612,6 +612,11 @@ int REST_DDF_PostBundles(const ApiRequest &req, ApiResponse &rsp)
return REQ_READY_SEND;
}

#if 1
// The file extension was changed from .ddf to .ddb in v2.27.4-beta.
// In case the same bundle with .ddf extension exists, the file will be deleted
// so that only a .ddb will exists.
{
{
U_SStream ssPath;
U_sstream_init(&ssPath, bundlePath, MAX_PATH_LENGTH);
Expand All @@ -621,6 +626,23 @@ int REST_DDF_PostBundles(const ApiRequest &req, ApiResponse &rsp)
U_sstream_put_str(&ssPath, ".ddf");
}

if (FS_OpenFile(&fp, FS_MODE_R, bundlePath))
{
FS_CloseFile(&fp);
FS_DeleteFile(bundlePath);
}
}
#endif

{
U_SStream ssPath;
U_sstream_init(&ssPath, bundlePath, MAX_PATH_LENGTH);
U_sstream_put_str(&ssPath, qPrintable(loc));
U_sstream_put_str(&ssPath, "/");
U_sstream_put_str(&ssPath, bundleHashStr);
U_sstream_put_str(&ssPath, ".ddb");
}

if (FS_OpenFile(&fp, FS_MODE_R, bundlePath))
{
FS_CloseFile(&fp);
Expand Down

0 comments on commit 516045b

Please sign in to comment.