Skip to content

Commit e6084df

Browse files
authored
Merge pull request #40 from KWB-R/dev
New release v0.4.0
2 parents e6b961f + 9a5c597 commit e6084df

33 files changed

+238
-243
lines changed

.github/workflows/R-CMD-check.yaml

+6-14
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
config:
25-
- {os: macOS-latest, r: 'release'}
26-
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
27-
- {os: windows-latest, r: 'devel'}
25+
- {os: macOS-latest, r: 'release'}
26+
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
27+
- {os: windows-latest, r: 'devel'}
2828
- {os: windows-latest, r: 'oldrel'}
2929
- {os: windows-latest, r: 'release'}
3030

@@ -39,11 +39,11 @@ jobs:
3939
steps:
4040
- uses: actions/checkout@v2
4141

42-
- uses: r-lib/actions/setup-r@master
42+
- uses: r-lib/actions/setup-r@v2
4343
with:
4444
r-version: ${{ matrix.config.r }}
4545

46-
- uses: r-lib/actions/setup-pandoc@master
46+
- uses: r-lib/actions/setup-pandoc@v2
4747

4848
- name: Query dependencies
4949
run: |
@@ -59,14 +59,6 @@ jobs:
5959
key: ${{ runner.os }}-r-${{ matrix.config.r }}-3-${{ hashFiles('depends.Rds') }}
6060
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-3-
6161

62-
- name: Install system dependencies
63-
if: runner.os == 'Linux'
64-
env:
65-
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
66-
run: |
67-
Rscript -e "remotes::install_github('r-hub/sysreqs')"
68-
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
69-
sudo -s eval "$sysreqs"
7062
- name: Install dependencies
7163
run: |
7264
remotes::install_deps(dependencies = TRUE)
@@ -79,7 +71,7 @@ jobs:
7971

8072
- name: Upload check results
8173
if: failure()
82-
uses: actions/upload-artifact@master
74+
uses: actions/upload-artifact@v4
8375
with:
8476
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
8577
path: check

.github/workflows/pkgdown.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v2
2020

21-
- uses: r-lib/actions/setup-r@master
21+
- uses: r-lib/actions/setup-r@v2
2222

23-
- uses: r-lib/actions/setup-pandoc@master
23+
- uses: r-lib/actions/setup-pandoc@v2
2424

2525
- name: Query dependencies
2626
run: |

.github/workflows/pr-commands.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1212
steps:
1313
- uses: actions/checkout@v2
14-
- uses: r-lib/actions/pr-fetch@master
14+
- uses: r-lib/actions/pr-fetch@v2
1515
with:
1616
repo-token: ${{ secrets.GITHUB_TOKEN }}
17-
- uses: r-lib/actions/setup-r@master
17+
- uses: r-lib/actions/setup-r@v2
1818
- name: Install dependencies
1919
run: Rscript -e 'install.packages(c("remotes", "roxygen2"))' -e 'remotes::install_deps(dependencies = TRUE)'
2020
- name: Document
@@ -23,7 +23,7 @@ jobs:
2323
run: |
2424
git add man/\* NAMESPACE
2525
git commit -m 'Document'
26-
- uses: r-lib/actions/pr-push@master
26+
- uses: r-lib/actions/pr-push@v2
2727
with:
2828
repo-token: ${{ secrets.GITHUB_TOKEN }}
2929
style:
@@ -34,10 +34,10 @@ jobs:
3434
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
3535
steps:
3636
- uses: actions/checkout@v2
37-
- uses: r-lib/actions/pr-fetch@master
37+
- uses: r-lib/actions/pr-fetch@v2
3838
with:
3939
repo-token: ${{ secrets.GITHUB_TOKEN }}
40-
- uses: r-lib/actions/setup-r@master
40+
- uses: r-lib/actions/setup-r@v2
4141
- name: Install dependencies
4242
run: Rscript -e 'install.packages("styler")'
4343
- name: Style
@@ -46,6 +46,6 @@ jobs:
4646
run: |
4747
git add \*.R
4848
git commit -m 'Style'
49-
- uses: r-lib/actions/pr-push@master
49+
- uses: r-lib/actions/pr-push@v2
5050
with:
5151
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-coverage.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v2
2323

24-
- uses: r-lib/actions/setup-r@master
24+
- uses: r-lib/actions/setup-r@v2
2525

26-
- uses: r-lib/actions/setup-pandoc@master
26+
- uses: r-lib/actions/setup-pandoc@v2
2727

2828
- name: Query dependencies
2929
run: |

DESCRIPTION

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: kwb.nextcloud
22
Title: R Package for Accessing Nextcloud Using WebDAV API
3-
Version: 0.3.0
3+
Version: 0.4.0
44
Authors@R: c(
55
person("Michael", "Rustler", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-0647-7726")),
@@ -16,9 +16,9 @@ License: MIT + file LICENSE
1616
URL: https://github.com/KWB-R/kwb.nextcloud
1717
BugReports: https://github.com/KWB-R/kwb.nextcloud/issues
1818
Imports:
19-
httr (>= 1.4.1),
19+
httr (>= 1.4.6),
2020
kwb.file (>= 0.3.1),
21-
kwb.utils (>= 0.6.0),
21+
kwb.utils (>= 0.13.0),
2222
xml2 (>= 1.3.2)
2323
Suggests:
2424
covr,
@@ -33,4 +33,4 @@ Remotes:
3333
Encoding: UTF-8
3434
LazyData: true
3535
Roxygen: list(markdown = TRUE)
36-
RoxygenNote: 7.1.2
36+
RoxygenNote: 7.3.1

NAMESPACE

+8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ export(compare_file_info_files)
55
export(create_folder)
66
export(delete_file_or_folder)
77
export(download_files)
8+
export(file_exists)
9+
export(get_file_versions)
810
export(get_version_info)
911
export(list_file_versions)
1012
export(list_files)
1113
export(move_file_or_folder)
14+
export(path_to_file_href)
1215
export(upload_file)
1316
importFrom(httr,GET)
1417
importFrom(httr,VERB)
@@ -17,18 +20,23 @@ importFrom(httr,headers)
1720
importFrom(httr,http_error)
1821
importFrom(kwb.file,remove_common_root)
1922
importFrom(kwb.utils,catAndRun)
23+
importFrom(kwb.utils,createDirectories)
2024
importFrom(kwb.utils,createDirectory)
2125
importFrom(kwb.utils,defaultIfNULL)
2226
importFrom(kwb.utils,excludeNULL)
27+
importFrom(kwb.utils,indent)
28+
importFrom(kwb.utils,isTryError)
2329
importFrom(kwb.utils,listToDepth)
2430
importFrom(kwb.utils,moveColumnsToFront)
2531
importFrom(kwb.utils,noFactorDataFrame)
2632
importFrom(kwb.utils,orderBy)
33+
importFrom(kwb.utils,removeLeadingSlashes)
2734
importFrom(kwb.utils,renameColumns)
2835
importFrom(kwb.utils,safeRowBindAll)
2936
importFrom(kwb.utils,selectColumns)
3037
importFrom(kwb.utils,stringList)
3138
importFrom(kwb.utils,toLookupList)
39+
importFrom(kwb.utils,uniqueDirnames)
3240
importFrom(utils,read.csv2)
3341
importFrom(utils,read.table)
3442
importFrom(utils,write.csv2)

NEWS.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# [kwb.nextcloud 0.4.0](https://github.com/KWB-R/kwb.nextcloud/releases/tag/v0.4.0) <small>2024-10-15</small>
2+
3+
* Add `file_exists()`
4+
* Add `get_file_versions()`
5+
* Fix bug in `path_to_file_href()` that occurred when a user name contained
6+
spaces. Document and export this function.
7+
* `download_files()`: Add argument `dbg`
8+
* `get_version_info()`: Add argument `dbg`
9+
* Deprecate `list_file_versions()`
10+
111
# [kwb.nextcloud 0.3.0](https://github.com/KWB-R/kwb.nextcloud/releases/tag/v0.3.0) <small>2021-06-03</small>
212

313
* Add `move_file_or_folder()`: see [Moving files and folders](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#moving-files-and-folders-rfc4918)

R/download_files.R

+20-9
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
#' \code{kwb.nextcloud:::nextcloud_user}
1313
#' @param auth authentication as returned by
1414
#' \code{kwb.nextcloud:::nextcloud_user}
15-
#' @importFrom kwb.utils defaultIfNULL
15+
#' @param dbg logical indicating whether or not to show debug messages
16+
#' @importFrom kwb.utils createDirectories defaultIfNULL uniqueDirnames
1617
#' @importFrom kwb.file remove_common_root
1718
#' @export
1819
#'
1920
download_files <- function(
2021
hrefs = NULL,
21-
target_dir = create_download_dir("nextcloud_"),
22+
target_dir = create_download_dir("nextcloud_", dbg = dbg),
2223
paths = NULL,
2324
user = nextcloud_user(),
24-
auth = nextcloud_auth()
25+
auth = nextcloud_auth(),
26+
dbg = TRUE
2527
)
2628
{
2729
#kwb.utils::assignPackageObjects("kwb.nextcloud")
@@ -44,10 +46,13 @@ download_files <- function(
4446
}
4547

4648
# Keep only the necessary tree structure
47-
target_paths <- kwb.file::remove_common_root(paths_decoded)
49+
target_paths <- kwb.file::remove_common_root(paths_decoded, dbg = FALSE)
4850

4951
# Create required target folders
50-
create_directories(file.path(target_dir, unique_dirnames(target_paths)))
52+
kwb.utils::createDirectories(
53+
file.path(target_dir, kwb.utils::uniqueDirnames(target_paths)),
54+
dbg = dbg
55+
)
5156

5257
# Create the full paths to the target files
5358
target_files <- file.path(target_dir, target_paths)
@@ -56,7 +61,7 @@ download_files <- function(
5661
FUN = download_from_href,
5762
hrefs,
5863
target_files,
59-
MoreArgs = list(auth = auth),
64+
MoreArgs = list(auth = auth, dbg = dbg),
6065
SIMPLIFY = FALSE,
6166
USE.NAMES = FALSE
6267
))
@@ -66,12 +71,17 @@ download_files <- function(
6671

6772
#' @importFrom kwb.utils catAndRun
6873
#' @keywords internal
69-
download_from_href <- function(href, target_file, auth = nextcloud_auth())
74+
download_from_href <- function(
75+
href,
76+
target_file,
77+
auth = nextcloud_auth(),
78+
dbg = TRUE
79+
)
7080
{
7181
# Expect the target directory to exist
7282
stopifnot(file.exists(dirname(target_file)))
7383

74-
kwb.utils::catAndRun(paste("Downloading", href), {
84+
kwb.utils::catAndRun(paste("Downloading", href), dbg = dbg, {
7585

7686
response <- nextcloud_request(href, "GET", auth)
7787

@@ -82,14 +92,15 @@ download_from_href <- function(href, target_file, auth = nextcloud_auth())
8292
# write_content_to_file --------------------------------------------------------
8393

8494
#' @importFrom httr content headers
95+
#' @importFrom kwb.utils isTryError
8596
#' @keywords internal
8697
write_content_to_file <- function(response, target_file)
8798
{
8899
content <- httr::content(response, type = "application/octet-stream")
89100

90101
result <- try(writeBin(content, target_file))
91102

92-
if (is_try_error(result)) {
103+
if (kwb.utils::isTryError(result)) {
93104

94105
stop(
95106
"Could not write the response data with writeBin(). ",

R/file_exists.R

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#' Does a File Exist on the Nextcloud Server?
2+
#'
3+
#' @param path path to the file
4+
#' @return \code{TRUE} if the file exists, else \code{FALSE}
5+
#' @export
6+
file_exists <- function(path)
7+
{
8+
stopifnot(is.character(path), length(path) == 1L)
9+
10+
basename(path) %in% list_files(dirname(path), silent = TRUE)
11+
}

R/get_file_versions.R

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# get_file_versions ------------------------------------------------------------
2+
3+
#' Get Information on Versions of Given Files
4+
#'
5+
#' @param file_info data frame as returned by \code{\link{list_files}} when
6+
#' being called with \code{full_info = TRUE}
7+
#' @returns data frame
8+
#' @importFrom kwb.utils moveColumnsToFront selectColumns
9+
#' @export
10+
get_file_versions <- function(file_info)
11+
{
12+
# Remove information on directories
13+
file_info <- file_info[!kwb.utils::selectColumns(file_info, "isdir"), ]
14+
15+
if (nrow(file_info) == 0L) {
16+
message("There are no (non-directory) files within file_info.")
17+
return()
18+
}
19+
20+
# Get version information for the remaining files
21+
file_ids <- kwb.utils::selectColumns(file_info, "fileid")
22+
version_info <- get_version_info(file_ids, dbg = FALSE)
23+
24+
if (is.null(version_info)) {
25+
return()
26+
}
27+
28+
columns_file_info <- c("fileid", "file", "lastmodified", "etag")
29+
columns_version_info <- c("fileid", "version", "href")
30+
31+
result <- merge(
32+
x = kwb.utils::selectColumns(file_info, columns_file_info),
33+
y = kwb.utils::selectColumns(version_info, columns_version_info),
34+
by = "fileid"
35+
)
36+
37+
kwb.utils::moveColumnsToFront(
38+
result,
39+
columns = c("fileid", "file", "version")
40+
)
41+
}

0 commit comments

Comments
 (0)