Ejemplo n.º 1
0
//===----------------------------------------------------------------------===//
// Client
//===----------------------------------------------------------------------===//
DirEntries Client::list(const char* pPathOrURL,
                        svn_opt_revision_t* pRevision,
                        bool pRecurse) throw(ClientException)
{
  Pool pool;

  apr_hash_t* hash;
  svn_error_t* error = svn_client_ls(&hash, pPathOrURL, pRevision, pRecurse,
                                     m_Context, pool.handler());

  if (nullptr != error)
    throw ClientException(error);

  DirEntries entries;
  apr_hash_index_t* item = apr_hash_first(pool.handler(), hash);
  while (nullptr != item) {
    const char* entryname = nullptr;
    svn_dirent_t* dirent;
    apr_hash_this(item, (const void **)&entryname, nullptr, (void **)&dirent);
    entries.push_back(DirEntry(entryname, dirent));

    item = apr_hash_next(item);
  }
  return entries;
}
Ejemplo n.º 2
0
  static svn_revnum_t
  remoteStatus(Client * client,
               const char * path,
               const bool descend,
               StatusEntries & entries,
               Context * /*context*/)
  {
    Revision rev(Revision::HEAD);
    DirEntries dirEntries = client->list(path, rev, descend);
    DirEntries::const_iterator it;
    svn_revnum_t revnum = 0;

    for (it = dirEntries.begin(); it != dirEntries.end(); it++)
    {
      const DirEntry & dirEntry = *it;

      entries.push_back(dirEntryToStatus(path, dirEntry));
    }

    if (dirEntries.size() > 0)
      revnum = dirEntries[0].createdRev();


    return revnum;
  }
Ejemplo n.º 3
0
static jobjectArray java_io_File_listImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
    // Read the directory entries into an intermediate form.
    DirEntries files;
    if (!readDirectory(env, pathBytes, files)) {
        return NULL;
    }
    // Translate the intermediate form into a Java String[].
    jclass stringClass = env->FindClass("java/lang/String");
    if (stringClass == NULL) {
        return NULL;
    }
    jobjectArray result = env->NewObjectArray(files.size(), stringClass, NULL);
    for (int i = 0; files.size() != 0; files.pop_front(), ++i) {
        jstring javaFilename = env->NewStringUTF(files.front());
        if (env->ExceptionCheck()) {
            return NULL;
        }
        env->SetObjectArrayElement(result, i, javaFilename);
        if (env->ExceptionCheck()) {
            return NULL;
        }
        env->DeleteLocalRef(javaFilename);
    }
    return result;
}
Ejemplo n.º 4
0
 static svn_error_t*
 listEntriesFunc(void *baton, const char *path,
       const svn_dirent_t *dirent, const svn_lock_t *lock,
       const char *abs_path, apr_pool_t *pool)
 {
   if (!isEmpty(path))
   {
     DirEntries * entries = static_cast<DirEntries *>(baton);
     entries->push_back(
       DirEntry(path, const_cast<svn_dirent_t *>(dirent), lock));
   }
   return 0;
 }
Ejemplo n.º 5
0
static jobjectArray File_listImpl(JNIEnv* env, jclass, jstring javaPath) {
    // Read the directory entries into an intermediate form.
    DirEntries files;
    if (!readDirectory(env, javaPath, files)) {
        return NULL;
    }
    // Translate the intermediate form into a Java String[].
    jobjectArray result = env->NewObjectArray(files.size(), JniConstants::stringClass, NULL);
    for (int i = 0; files.size() != 0; files.pop_front(), ++i) {
        ScopedLocalRef<jstring> javaFilename(env, env->NewStringUTF(files.front()));
        if (env->ExceptionCheck()) {
            return NULL;
        }
        env->SetObjectArrayElement(result, i, javaFilename.get());
        if (env->ExceptionCheck()) {
            return NULL;
        }
    }
    return result;
}
Ejemplo n.º 6
0
// Reads the directory referred to by 'pathBytes', adding each directory entry
// to 'entries'.
static bool readDirectory(JNIEnv* env, jstring javaPath, DirEntries& entries) {
    ScopedUtfChars path(env, javaPath);
    if (path.c_str() == NULL) {
        return false;
    }

    ScopedReaddir dir(path.c_str());
    const char* filename;
    while ((filename = dir.next()) != NULL) {
        if (strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) {
            // TODO: this hides allocation failures from us. Push directory iteration up into Java?
            entries.push_back(filename);
        }
    }
    return !dir.isBad();
}
Ejemplo n.º 7
0
// Reads the directory referred to by 'pathBytes', adding each directory entry
// to 'entries'.
static bool readDirectory(JNIEnv* env, jbyteArray pathBytes, DirEntries& entries) {
    ScopedByteArray path(env, pathBytes);
    ScopedReaddir dir(&path[0]);
    if (dir.isBad()) {
        return false;
    }
    const char* filename;
    while ((filename = dir.next()) != NULL) {
        if (strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) {
            if (!entries.push_front(filename)) {
                jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 8
0
// Reads the directory referred to by 'pathBytes', adding each directory entry
// to 'entries'.
static bool readDirectory(JNIEnv* env, jstring javaPath, DirEntries& entries) {
    ScopedUtfChars path(env, javaPath);
    if (path.c_str() == NULL) {
        return false;
    }

    ScopedReaddir dir(path.c_str());
    if (dir.isBad()) {
        return false;
    }
    const char* filename;
    while ((filename = dir.next()) != NULL) {
        if (strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) {
            if (!entries.push_front(filename)) {
                jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
                return false;
            }
        }
    }
    return true;
}