Ejemplo n.º 1
0
TEST_F(FilesTest, BrowseTest)
{
  Files files;
  process::UPID upid("files", process::address());

  ASSERT_SOME(os::mkdir("1/2"));
  ASSERT_SOME(os::mkdir("1/3"));
  ASSERT_SOME(os::write("1/two", "two"));
  ASSERT_SOME(os::write("1/three", "three"));

  AWAIT_EXPECT_READY(files.attach("1", "one"));

  // Get the listing.
  struct stat s;
  JSON::Array expected;
  ASSERT_EQ(0, stat("1/2", &s));
  expected.values.push_back(jsonFileInfo("one/2", s));
  ASSERT_EQ(0, stat("1/3", &s));
  expected.values.push_back(jsonFileInfo("one/3", s));
  ASSERT_EQ(0, stat("1/three", &s));
  expected.values.push_back(jsonFileInfo("one/three", s));
  ASSERT_EQ(0, stat("1/two", &s));
  expected.values.push_back(jsonFileInfo("one/two", s));

  Future<Response> response =
      process::http::get(upid, "browse.json", "path=one/");

  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
  AWAIT_EXPECT_RESPONSE_BODY_EQ(stringify(expected), response);

  response = process::http::get(upid, "browse.json", "path=one%2F");

  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
  AWAIT_EXPECT_RESPONSE_BODY_EQ(stringify(expected), response);

  response = process::http::get(upid, "browse.json", "path=one");

  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
  AWAIT_EXPECT_RESPONSE_BODY_EQ(stringify(expected), response);

  // Empty listing.
  response = process::http::get(upid, "browse.json", "path=one/2");

  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
  AWAIT_EXPECT_RESPONSE_BODY_EQ(stringify(JSON::Array()), response);

  // Missing dir.
  AWAIT_EXPECT_RESPONSE_STATUS_EQ(
      NotFound().status,
      process::http::get(upid, "browse.json", "path=missing"));
}
Ejemplo n.º 2
0
QString DTrash::createJsonRecordForFile(const QString& collectionPath, const QString& imagePath)
{
    QJsonObject jsonObjForImg;

    QJsonValue pathJsonVal(imagePath);
    QJsonValue timestampJsonVal(QDateTime::currentDateTime().toString());

    jsonObjForImg.insert(PATH_JSON_KEY, pathJsonVal);
    jsonObjForImg.insert(DELETIONTIMESTAMP_JSON_KEY, timestampJsonVal);

    QJsonDocument jsonDocForImg(jsonObjForImg);

    QFileInfo imgFileInfo(imagePath);

    QString jsonFileName = getAvialableJsonFilePathInTrash(collectionPath, imgFileInfo.baseName());

    QFile jsonFileForImg(jsonFileName);

    QFileInfo jsonFileInfo(jsonFileName);

    if(!jsonFileForImg.open(QFile::WriteOnly))
        return jsonFileInfo.baseName();

    jsonFileForImg.write(jsonDocForImg.toJson());
    jsonFileForImg.close();

    return jsonFileInfo.baseName();
}
Ejemplo n.º 3
0
QString DTrash::getAvialableJsonFilePathInTrash(const QString& collectionPath, const QString& baseName, int version)
{
    QString pathToCreateJsonFile = collectionPath + QLatin1Char('/') +
                                   TRASH_FOLDER + QLatin1Char('/') +
                                   INFO_FOLDER + QLatin1Char('/') +
                                   baseName +
                                   (version ? QString::number(version) : QLatin1String("")) +
                                   INFO_FILE_EXTENSION;

    QFileInfo jsonFileInfo(pathToCreateJsonFile);

    if (jsonFileInfo.exists())
    {
        return getAvialableJsonFilePathInTrash(collectionPath, baseName, ++version);
    }
    else
    {
        return pathToCreateJsonFile;
    }
}