Giter Site home page Giter Site logo

Can't restore time about recipes HOT 9 CLOSED

coatless avatar coatless commented on August 23, 2024
Can't restore time

from recipes.

Comments (9)

s-u avatar s-u commented on August 23, 2024

@coatless you have sudo in the wrong place - you don't want to run curl as root, you want to run tar as root, so it's sudo tar .... However, note that you cannot supply the password on stdin in that case as curl is already the stdin. You may be better off simply using download.file() instead and untar in a separate step.

That said, as a user I'd be horrified that you are asking for user password with echo, so I'd recommend relying on the system tools instead.

from recipes.

coatless avatar coatless commented on August 23, 2024

@s-u system is being used in this demo for an MVP. The full setup is given as:

shell_sudo_command = function(cmd, password, prefix = "sudo -kS ") {
    cmd_with_sudo = paste0(prefix, cmd)
    if (is.null(password)) {
        system(cmd_with_sudo, input = password_prompt("Enter user password to run command:"))
    } else {
        system(cmd_with_sudo, input = password)
    }
}

password_prompt = function(msg) {
    if(interactive()) {
        if(requireNamespace("rstudioapi", quietly = TRUE) && rstudioapi::isAvailable()) {
            rstudioapi::askForPassword(msg)
        } else {
            readline(msg)
        }
    } else {
        stop("Unable to request password as the session is not being run interactively.")
    }
}

When possible, we'll accept the password via rstudioapi::askForPassword() prompt. Is there a better way of asking and storing a password using plain R?

The goal here is to avoid exposing the user to terminal.

from recipes.

s-u avatar s-u commented on August 23, 2024

This is OT here, but fair enough - I'd just never allow echoed password entry no matter what, not even as fall-back. You can use askpass::askpass() which uses safe native entry regardless of the UI used.

from recipes.

coatless avatar coatless commented on August 23, 2024

Apologies for the off-topic component. I'll re-write using askpass()

Back on topic though, I'm still seeing the Can't restore time error:

# Download file
download.file(
    "https://mac.R-project.org/bin/darwin17/x86_64/xz-5.2.5-darwin.17-x86_64.tar.xz",
    "xz-5.2.5-darwin.17-x86_64.tar.xz"
)

# Install command
cmd = "sudo -kS tar fxj xz-5.2.5-darwin.17-x86_64.tar.xz -C /"
system(cmd, input = readline("Password:"))

# Password:usr/local/: Can't restore time
# tar: Error exit delayed from previous errors.

Or:

download.file(
    "https://mac.R-project.org/bin/darwin17/x86_64/xz-5.2.5-darwin.17-x86_64.tar.xz",
    "xz-5.2.5-darwin.17-x86_64.tar.xz"
)

untar("xz-5.2.5-darwin.17-x86_64.tar.xz", exdir = "/")

Yields:

usr/local/: Can't restore time
usr/local/bin/: Can't restore time
usr/local/include/: Can't restore time
usr/local/lib/: Can't restore time
usr/local/pkg/: Can't restore time
usr/local/share/: Can't restore time
usr/local/share/doc/: Can't restore time
usr/local/share/man/: Can't restore time
usr/local/share/man/man1/: Can't restore time

from recipes.

s-u avatar s-u commented on August 23, 2024

One comment on the process there - note that even root is not guaranteed to have access to user's files (on macOS places like Documents, Download etc. are not readable even by root), so you want to make sure if you download the file you do so into tempdir().

from recipes.

s-u avatar s-u commented on August 23, 2024

The above is expected, on macOS not even root can change the attributes of /usr/local. It is just a note, not an error. You can avoid it by not extracting outside of the prefix (as was illustrated in the issue you quoted: b060377).

from recipes.

coatless avatar coatless commented on August 23, 2024

Still observing a similar issue even with the modifications into tempdir() and adding the --strip 2 option.

save_location = file.path(tempdir(), "gdal-3.4.2-darwin.17-x86_64.tar.xz")
download.file(
    "https://mac.R-project.org/bin/darwin17/x86_64/gdal-3.4.2-darwin.17-x86_64.tar.xz",
    save_location
)
untar(save_location, exdir = "/usr/local", extras = "--strip 2")

Switching to a different package, e.g. gdal gives:

bin/: Can't restore time
include/: Can't restore time
lib/: Can't restore time
pkg/: Can't restore time
share/: Can't restore time
share/gdal/: Can't create 'share/gdal'
share/gdal/bag_template.xml: Failed to create dir 'share/gdal'
share/gdal/cubewerx_extra.wkt: Failed to create dir 'share/gdal'
share/gdal/default.rsc: Failed to create dir 'share/gdal'
share/gdal/ecw_cs.wkt: Failed to create dir 'share/gdal'
share/gdal/eedaconf.json: Failed to create dir 'share/gdal'
share/gdal/epsg.wkt: Failed to create dir 'share/gdal'
share/gdal/esri_StatePlane_extra.wkt: Failed to create dir 'share/gdal'
share/gdal/gdalicon.png: Failed to create dir 'share/gdal'
share/gdal/GDALLogoBW.svg: Failed to create dir 'share/gdal'

Command output:

'/usr/bin/tar -xf '/var/folders/b0/vt_1hj2d6yd8myx9lwh81pww0000gn/T//RtmpYvXNkT/gdal-3.4.2-darwin.17-x86_64.tar.xz' -C '/usr/local' --strip 2' returned error code 1

from recipes.

s-u avatar s-u commented on August 23, 2024

I think you missed sudo here?

from recipes.

coatless avatar coatless commented on August 23, 2024

@s-u yes, untar() doesn't seem to have that option.

With sudo present, everything worked beautiful. I settled on:

package_url = "https://mac.R-project.org/bin/darwin17/x86_64/xz-5.2.5-darwin.17-x86_64.tar.xz"
save_location = file.path(tempdir(), basename(package_url))
download.file(
    package_url,
    save_location
)

cmd = paste0("sudo -kS tar fxj ", save_location," -C /usr/local/ --strip 2")
system(cmd, input = askpass::askpass())

Thanks again for the help!

from recipes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.