Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Patricia Ferreira Newsgroups: pt.comp.programacao Subject: Re: sobre common lisp e o sistema de arquivos Date: Mon, 22 Jan 2024 16:14:33 -0300 Organization: A noiseless patient Spider Lines: 87 Message-ID: <878r4h9o4m.fsf@example.com> References: <87v87la7zs.fsf@example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="9d8e47db7029a7e6a20558c79fff5b69"; logging-data="919550"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hy5YRMmM+5ao/5drpPSA4TSFt++OL96k=" Cancel-Lock: sha1:t3SCwL1HKmYtnzwEtCz6nuKXuB0= sha1:Sul1IrJaqjxXFuV4R8+E3gNwXhU= Xref: csiph.com pt.comp.programacao:185 Patricia Ferreira writes: > Tenho lido vários pedaços de documentação Common Lisp por aí, livros > incluindo. Antes de falar com o sistema de arquivos, vale a pena ler o > capítulo 14 de Peter Seibel ``Practical Common Lisp''. > > Files and File I/O > https://gigamonkeys.com/book/files-and-file-io.html > > ``When pathnames were designed, the set of file systems in general use > was quite a bit more variegated than those in common use today. > Consequently, some nooks and crannies of the pathname abstraction make > little sense if all you're concerned about is representing Unix or > Windows filenames.'' Eis o tipo de armadilha contras as quais estamos. --8<---------------cut here---------------start------------->8--- NNTPD> (rename-file (make-pathname :name "1" :type "tmp") (make-pathname :name "2" :type "txt")) Failed to find the TRUENAME of "c:\\[...]\\quicklisp\\local-projects\\nntp\\groups\\1.tmp": --8<---------------cut here---------------end--------------->8--- Lol. Não consigo nem renomear um arquivo. --8<---------------cut here---------------start------------->8--- NNTPD> *default-pathname-defaults* #P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test" NNTPD> (sb-posix:getcwd) "c:\\[...]\\quicklisp\\local-projects\\nntp\\groups\\local.test" --8<---------------cut here---------------end--------------->8--- Em outras palavras---rename-file deveria operar nesse diretório aí e não em groups/. O que poderia estar errado? Veja que sei o que estou fazendo---sei renomear um arquivo e tenho curso *superior* e tal. --8<---------------cut here---------------start------------->8--- * *default-pathname-defaults* #P"c:/sys/emacs/usr/quicklisp/local-projects/nntp/groups/local.test/" * (rename-file "1.tmp" "1.txt") #P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test/1.txt" #P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test/1.tmp" #P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test/1.txt" --8<---------------cut here---------------end--------------->8--- Isso prova. Onde está o problema? O problema está no fato de que aí na segunda tentativa, o diretório termina com uma barra. No primeiro caso, onde a falha ocorre, não há uma barra. Common Lisp assume que aquilo então é um arquivo e não um diretório. ``Ele'' então pega o diretório daquele arquivo, que é groups/. Peter Seibel me avisou disso, mas iniciantes são assim. Como disse a USENET uma vez---even if you dip a user in an ocean of clues, it will comes out clueless. Lol. --8<---------------cut here---------------start------------->8--- When dealing with pathnames that name directories, you need to be aware of one wrinkle. Pathnames separate the directory and name components, but Unix and Windows consider directories just another kind of file. Thus, on those systems, every directory has two different pathname representations. One representation, which I'll call file form, treats a directory like any other file and puts the last element of the namestring into the name and type components. The other representation, directory form, places all the elements of the name in the directory component, leaving the name and type components NIL. When you create pathnames with MAKE-PATHNAME, you can control which form you get, but you need to be careful when dealing with namestrings. All current implementations create file form pathnames unless the namestring ends with a path separator. But you can't rely on user-supplied namestrings necessarily being in one form or another. For instance, suppose you've prompted the user for a directory to save a file in and they entered "/home/peter". If you pass that value as the :defaults argument of MAKE-PATHNAME like this: (make-pathname :name "foo" :type "txt" :defaults user-supplied-name) you'll end up saving the file in /home/foo.txt rather than the intended /home/peter/foo.txt because the "peter" in the namestring will be placed in the name component when user-supplied-name is converted to a pathname. -- Peter Seibel, capítulo 14. --8<---------------cut here---------------end--------------->8---